From b5fb63d09139aeaad2348afe512dd33229a9481b Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Tue, 23 Jun 2020 13:39:19 +0300 Subject: [PATCH] *: specify first state root index in config --- config/protocol.testnet.yml | 2 ++ pkg/config/protocol_config.go | 12 +++++++----- pkg/network/server.go | 13 ++++++++++++- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/config/protocol.testnet.yml b/config/protocol.testnet.yml index 711485d26..8ccb17005 100644 --- a/config/protocol.testnet.yml +++ b/config/protocol.testnet.yml @@ -2,6 +2,8 @@ ProtocolConfiguration: Magic: 1953787457 AddressVersion: 23 SecondsPerBlock: 15 + EnableStateRoot: true + StateRootEnableIndex: 4380100 LowPriorityThreshold: 0.000 MemPoolSize: 50000 StandbyValidators: diff --git a/pkg/config/protocol_config.go b/pkg/config/protocol_config.go index 1974bd72e..dff592038 100644 --- a/pkg/config/protocol_config.go +++ b/pkg/config/protocol_config.go @@ -36,11 +36,13 @@ type ( MaxFreeTransactionsPerBlock int `yaml:"MaxFreeTransactionsPerBlock"` MemPoolSize int `yaml:"MemPoolSize"` // SaveStorageBatch enables storage batch saving before every persist. - SaveStorageBatch bool `yaml:"SaveStorageBatch"` - SecondsPerBlock int `yaml:"SecondsPerBlock"` - SeedList []string `yaml:"SeedList"` - StandbyValidators []string `yaml:"StandbyValidators"` - SystemFee SystemFee `yaml:"SystemFee"` + SaveStorageBatch bool `yaml:"SaveStorageBatch"` + SecondsPerBlock int `yaml:"SecondsPerBlock"` + SeedList []string `yaml:"SeedList"` + StandbyValidators []string `yaml:"StandbyValidators"` + // StateRootEnableIndex specifies starting height for state root calculations and exchange. + StateRootEnableIndex uint32 `yaml:"StateRootEnableIndex"` + SystemFee SystemFee `yaml:"SystemFee"` // Whether to verify received blocks. VerifyBlocks bool `yaml:"VerifyBlocks"` // Whether to verify transactions in received blocks. diff --git a/pkg/network/server.go b/pkg/network/server.go index 709da94aa..9364da476 100644 --- a/pkg/network/server.go +++ b/pkg/network/server.go @@ -602,7 +602,8 @@ func (s *Server) handleGetHeadersCmd(p Peer, gh *payload.GetBlocks) error { // handleGetRootsCmd processees `getroots` request. 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 } count := gr.Count @@ -628,6 +629,9 @@ func (s *Server) handleRootsCmd(p Peer, rs *payload.StateRoots) error { return nil } h := s.chain.StateHeight() + if h < s.chain.GetConfig().StateRootEnableIndex { + h = s.chain.GetConfig().StateRootEnableIndex + } for i := range rs.Roots { if rs.Roots[i].Index <= h { continue @@ -642,6 +646,13 @@ func (s *Server) handleRootsCmd(p Peer, rs *payload.StateRoots) error { func (s *Server) requestStateRoot(p Peer) error { stateHeight := s.chain.StateHeight() hdrHeight := s.chain.BlockHeight() + enableIndex := s.chain.GetConfig().StateRootEnableIndex + if hdrHeight < enableIndex { + return nil + } + if stateHeight < enableIndex { + stateHeight = enableIndex - 1 + } count := uint32(payload.MaxStateRootsAllowed) if diff := hdrHeight - stateHeight; diff < count { count = diff