*: specify first state root index in config

This commit is contained in:
Evgenii Stratonikov 2020-06-23 13:39:19 +03:00
parent d128b55dbf
commit b5fb63d091
3 changed files with 21 additions and 6 deletions

View file

@ -2,6 +2,8 @@ ProtocolConfiguration:
Magic: 1953787457 Magic: 1953787457
AddressVersion: 23 AddressVersion: 23
SecondsPerBlock: 15 SecondsPerBlock: 15
EnableStateRoot: true
StateRootEnableIndex: 4380100
LowPriorityThreshold: 0.000 LowPriorityThreshold: 0.000
MemPoolSize: 50000 MemPoolSize: 50000
StandbyValidators: StandbyValidators:

View file

@ -40,6 +40,8 @@ type (
SecondsPerBlock int `yaml:"SecondsPerBlock"` SecondsPerBlock int `yaml:"SecondsPerBlock"`
SeedList []string `yaml:"SeedList"` SeedList []string `yaml:"SeedList"`
StandbyValidators []string `yaml:"StandbyValidators"` StandbyValidators []string `yaml:"StandbyValidators"`
// StateRootEnableIndex specifies starting height for state root calculations and exchange.
StateRootEnableIndex uint32 `yaml:"StateRootEnableIndex"`
SystemFee SystemFee `yaml:"SystemFee"` SystemFee SystemFee `yaml:"SystemFee"`
// Whether to verify received blocks. // Whether to verify received blocks.
VerifyBlocks bool `yaml:"VerifyBlocks"` VerifyBlocks bool `yaml:"VerifyBlocks"`

View file

@ -602,7 +602,8 @@ func (s *Server) handleGetHeadersCmd(p Peer, gh *payload.GetBlocks) error {
// handleGetRootsCmd processees `getroots` request. // handleGetRootsCmd processees `getroots` request.
func (s *Server) handleGetRootsCmd(p Peer, gr *payload.GetStateRoots) error { func (s *Server) handleGetRootsCmd(p Peer, gr *payload.GetStateRoots) error {
if !s.chain.GetConfig().EnableStateRoot { cfg := s.chain.GetConfig()
if !cfg.EnableStateRoot || gr.Start < cfg.StateRootEnableIndex {
return nil return nil
} }
count := gr.Count count := gr.Count
@ -628,6 +629,9 @@ func (s *Server) handleRootsCmd(p Peer, rs *payload.StateRoots) error {
return nil return nil
} }
h := s.chain.StateHeight() h := s.chain.StateHeight()
if h < s.chain.GetConfig().StateRootEnableIndex {
h = s.chain.GetConfig().StateRootEnableIndex
}
for i := range rs.Roots { for i := range rs.Roots {
if rs.Roots[i].Index <= h { if rs.Roots[i].Index <= h {
continue continue
@ -642,6 +646,13 @@ func (s *Server) handleRootsCmd(p Peer, rs *payload.StateRoots) error {
func (s *Server) requestStateRoot(p Peer) error { func (s *Server) requestStateRoot(p Peer) error {
stateHeight := s.chain.StateHeight() stateHeight := s.chain.StateHeight()
hdrHeight := s.chain.BlockHeight() hdrHeight := s.chain.BlockHeight()
enableIndex := s.chain.GetConfig().StateRootEnableIndex
if hdrHeight < enableIndex {
return nil
}
if stateHeight < enableIndex {
stateHeight = enableIndex - 1
}
count := uint32(payload.MaxStateRootsAllowed) count := uint32(payload.MaxStateRootsAllowed)
if diff := hdrHeight - stateHeight; diff < count { if diff := hdrHeight - stateHeight; diff < count {
count = diff count = diff