MCPcopy Create free account
hub / github.com/DNAProject/DNA / GetVbftConfigInfo

Function GetVbftConfigInfo

consensus/vbft/utils.go:132–186  ·  view source on GitHub ↗
(memdb *overlaydb.MemDB)

Source from the content-addressed store, hash-verified

130}
131
132func GetVbftConfigInfo(memdb *overlaydb.MemDB) (*config.VBFTConfig, error) {
133 //get governance view
134 goveranceview, err := GetGovernanceView(memdb)
135 if err != nil {
136 return nil, err
137 }
138
139 //get preConfig
140 preCfg := new(gov.PreConfig)
141 data, err := GetStorageValue(memdb, ledger.DefLedger, nutils.GovernanceContractAddress, []byte(gov.PRE_CONFIG))
142 if err != nil && err != scommon.ErrNotFound {
143 return nil, err
144 }
145 if data != nil {
146 err = preCfg.Deserialization(common.NewZeroCopySource(data))
147 if err != nil {
148 return nil, err
149 }
150 }
151
152 chainconfig := new(config.VBFTConfig)
153 if preCfg.SetView == goveranceview.View {
154 chainconfig = &config.VBFTConfig{
155 N: uint32(preCfg.Configuration.N),
156 C: uint32(preCfg.Configuration.C),
157 K: uint32(preCfg.Configuration.K),
158 L: uint32(preCfg.Configuration.L),
159 BlockMsgDelay: uint32(preCfg.Configuration.BlockMsgDelay),
160 HashMsgDelay: uint32(preCfg.Configuration.HashMsgDelay),
161 PeerHandshakeTimeout: uint32(preCfg.Configuration.PeerHandshakeTimeout),
162 MaxBlockChangeView: uint32(preCfg.Configuration.MaxBlockChangeView),
163 }
164 } else {
165 data, err := GetStorageValue(memdb, ledger.DefLedger, nutils.GovernanceContractAddress, []byte(gov.VBFT_CONFIG))
166 if err != nil {
167 return nil, err
168 }
169 cfg := new(gov.Configuration)
170 err = cfg.Deserialization(common.NewZeroCopySource(data))
171 if err != nil {
172 return nil, err
173 }
174 chainconfig = &config.VBFTConfig{
175 N: uint32(cfg.N),
176 C: uint32(cfg.C),
177 K: uint32(cfg.K),
178 L: uint32(cfg.L),
179 BlockMsgDelay: uint32(cfg.BlockMsgDelay),
180 HashMsgDelay: uint32(cfg.HashMsgDelay),
181 PeerHandshakeTimeout: uint32(cfg.PeerHandshakeTimeout),
182 MaxBlockChangeView: uint32(cfg.MaxBlockChangeView),
183 }
184 }
185 return chainconfig, nil
186}
187
188func GetPeersConfig(memdb *overlaydb.MemDB) ([]*config.VBFTPeerStakeInfo, error) {
189 goveranceview, err := GetGovernanceView(memdb)

Callers 1

getChainConfigFunction · 0.85

Calls 3

GetStorageValueFunction · 0.85
GetGovernanceViewFunction · 0.70
DeserializationMethod · 0.65

Tested by

no test coverage detected