From 582d489c902c0eba5b0d6f8f0effe744940e7b98 Mon Sep 17 00:00:00 2001 From: Evgeniy Stratonikov Date: Wed, 3 Nov 2021 12:55:33 +0300 Subject: [PATCH] dao: add `P2PStateExchangeExtensions` setting to `dao.Version` Signed-off-by: Evgeniy Stratonikov --- pkg/core/blockchain.go | 15 ++++++++++----- pkg/core/dao/dao.go | 16 +++++++++++----- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/pkg/core/blockchain.go b/pkg/core/blockchain.go index 2b4f6d556..a08375b81 100644 --- a/pkg/core/blockchain.go +++ b/pkg/core/blockchain.go @@ -306,11 +306,12 @@ func (bc *Blockchain) init() error { if err != nil { bc.log.Info("no storage version found! creating genesis block") ver = dao.Version{ - StoragePrefix: storage.STStorage, - StateRootInHeader: bc.config.StateRootInHeader, - P2PSigExtensions: bc.config.P2PSigExtensions, - KeepOnlyLatestState: bc.config.KeepOnlyLatestState, - Value: version, + StoragePrefix: storage.STStorage, + StateRootInHeader: bc.config.StateRootInHeader, + P2PSigExtensions: bc.config.P2PSigExtensions, + P2PStateExchangeExtensions: bc.config.P2PStateExchangeExtensions, + KeepOnlyLatestState: bc.config.KeepOnlyLatestState, + Value: version, } if err = bc.dao.PutVersion(ver); err != nil { return err @@ -342,6 +343,10 @@ func (bc *Blockchain) init() error { return fmt.Errorf("P2PSigExtensions setting mismatch (old=%t, new=%t", ver.P2PSigExtensions, bc.config.P2PSigExtensions) } + if ver.P2PStateExchangeExtensions != bc.config.P2PStateExchangeExtensions { + return fmt.Errorf("P2PStateExchangeExtensions setting mismatch (old=%t, new=%t", + ver.P2PStateExchangeExtensions, bc.config.P2PStateExchangeExtensions) + } if ver.KeepOnlyLatestState != bc.config.KeepOnlyLatestState { return fmt.Errorf("KeepOnlyLatestState setting mismatch: old=%v, new=%v", ver.KeepOnlyLatestState, bc.config.KeepOnlyLatestState) diff --git a/pkg/core/dao/dao.go b/pkg/core/dao/dao.go index 5387e4752..e0e9bad9b 100644 --- a/pkg/core/dao/dao.go +++ b/pkg/core/dao/dao.go @@ -378,16 +378,18 @@ func (dao *Simple) GetBlock(hash util.Uint256) (*block.Block, error) { // Version represents current dao version. type Version struct { - StoragePrefix storage.KeyPrefix - StateRootInHeader bool - P2PSigExtensions bool - KeepOnlyLatestState bool - Value string + StoragePrefix storage.KeyPrefix + StateRootInHeader bool + P2PSigExtensions bool + P2PStateExchangeExtensions bool + KeepOnlyLatestState bool + Value string } const ( stateRootInHeaderBit = 1 << iota p2pSigExtensionsBit + p2pStateExchangeExtensionsBit keepOnlyLatestStateBit ) @@ -413,6 +415,7 @@ func (v *Version) FromBytes(data []byte) error { v.StoragePrefix = storage.KeyPrefix(data[i+1]) v.StateRootInHeader = data[i+2]&stateRootInHeaderBit != 0 v.P2PSigExtensions = data[i+2]&p2pSigExtensionsBit != 0 + v.P2PStateExchangeExtensions = data[i+2]&p2pStateExchangeExtensionsBit != 0 v.KeepOnlyLatestState = data[i+2]&keepOnlyLatestStateBit != 0 return nil } @@ -426,6 +429,9 @@ func (v *Version) Bytes() []byte { if v.P2PSigExtensions { mask |= p2pSigExtensionsBit } + if v.P2PStateExchangeExtensions { + mask |= p2pStateExchangeExtensionsBit + } if v.KeepOnlyLatestState { mask |= keepOnlyLatestStateBit }