From b327308df882b53f47fd15fcf987f698d8b9cb57 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Thu, 5 Nov 2020 22:01:12 +0300 Subject: [PATCH] core/config: move MaxTraceableBlocks to configuration file Follow neo-project/neo#2042, use 2102400 setting for mainnet/testnet and 200000 for private networks. --- config/protocol.mainnet.yml | 1 + config/protocol.privnet.docker.four.yml | 1 + config/protocol.privnet.docker.one.yml | 1 + config/protocol.privnet.docker.single.yml | 1 + config/protocol.privnet.docker.three.yml | 1 + config/protocol.privnet.docker.two.yml | 1 + config/protocol.privnet.yml | 1 + config/protocol.testnet.yml | 1 + config/protocol.unit_testnet.single.yml | 1 + config/protocol.unit_testnet.yml | 1 + pkg/config/protocol_config.go | 2 ++ pkg/core/blockchain.go | 9 +++++++-- pkg/core/interop_system.go | 4 +--- 13 files changed, 20 insertions(+), 5 deletions(-) diff --git a/config/protocol.mainnet.yml b/config/protocol.mainnet.yml index 3fd8681e2..bed4f3d30 100644 --- a/config/protocol.mainnet.yml +++ b/config/protocol.mainnet.yml @@ -1,5 +1,6 @@ ProtocolConfiguration: Magic: 5195086 + MaxTraceableBlocks: 2102400 SecondsPerBlock: 15 MemPoolSize: 50000 StandbyCommittee: diff --git a/config/protocol.privnet.docker.four.yml b/config/protocol.privnet.docker.four.yml index 1dbe86087..87f796a57 100644 --- a/config/protocol.privnet.docker.four.yml +++ b/config/protocol.privnet.docker.four.yml @@ -1,5 +1,6 @@ ProtocolConfiguration: Magic: 56753 + MaxTraceableBlocks: 200000 SecondsPerBlock: 15 MemPoolSize: 50000 StandbyCommittee: diff --git a/config/protocol.privnet.docker.one.yml b/config/protocol.privnet.docker.one.yml index 64ec31fd1..113e43954 100644 --- a/config/protocol.privnet.docker.one.yml +++ b/config/protocol.privnet.docker.one.yml @@ -1,5 +1,6 @@ ProtocolConfiguration: Magic: 56753 + MaxTraceableBlocks: 200000 SecondsPerBlock: 15 MemPoolSize: 50000 StandbyCommittee: diff --git a/config/protocol.privnet.docker.single.yml b/config/protocol.privnet.docker.single.yml index 44a787944..38eff6dc5 100644 --- a/config/protocol.privnet.docker.single.yml +++ b/config/protocol.privnet.docker.single.yml @@ -1,5 +1,6 @@ ProtocolConfiguration: Magic: 56753 + MaxTraceableBlocks: 200000 SecondsPerBlock: 1 MemPoolSize: 50000 StandbyCommittee: diff --git a/config/protocol.privnet.docker.three.yml b/config/protocol.privnet.docker.three.yml index 1f02c5e76..8c0f892ee 100644 --- a/config/protocol.privnet.docker.three.yml +++ b/config/protocol.privnet.docker.three.yml @@ -1,5 +1,6 @@ ProtocolConfiguration: Magic: 56753 + MaxTraceableBlocks: 200000 SecondsPerBlock: 15 MemPoolSize: 50000 StandbyCommittee: diff --git a/config/protocol.privnet.docker.two.yml b/config/protocol.privnet.docker.two.yml index d16905874..ccd94a969 100644 --- a/config/protocol.privnet.docker.two.yml +++ b/config/protocol.privnet.docker.two.yml @@ -1,5 +1,6 @@ ProtocolConfiguration: Magic: 56753 + MaxTraceableBlocks: 200000 SecondsPerBlock: 15 MemPoolSize: 50000 StandbyCommittee: diff --git a/config/protocol.privnet.yml b/config/protocol.privnet.yml index f42acbf71..d10096a94 100644 --- a/config/protocol.privnet.yml +++ b/config/protocol.privnet.yml @@ -1,5 +1,6 @@ ProtocolConfiguration: Magic: 56753 + MaxTraceableBlocks: 200000 SecondsPerBlock: 15 MemPoolSize: 50000 StandbyCommittee: diff --git a/config/protocol.testnet.yml b/config/protocol.testnet.yml index a2caa370d..55002dd6a 100644 --- a/config/protocol.testnet.yml +++ b/config/protocol.testnet.yml @@ -1,5 +1,6 @@ ProtocolConfiguration: Magic: 1951352142 + MaxTraceableBlocks: 2102400 SecondsPerBlock: 15 MemPoolSize: 50000 StandbyCommittee: diff --git a/config/protocol.unit_testnet.single.yml b/config/protocol.unit_testnet.single.yml index 0d9646de6..3f655c658 100644 --- a/config/protocol.unit_testnet.single.yml +++ b/config/protocol.unit_testnet.single.yml @@ -1,5 +1,6 @@ ProtocolConfiguration: Magic: 42 + MaxTraceableBlocks: 200000 SecondsPerBlock: 1 MemPoolSize: 100 StandbyCommittee: diff --git a/config/protocol.unit_testnet.yml b/config/protocol.unit_testnet.yml index 3970409b1..c74b4168a 100644 --- a/config/protocol.unit_testnet.yml +++ b/config/protocol.unit_testnet.yml @@ -1,5 +1,6 @@ ProtocolConfiguration: Magic: 42 + MaxTraceableBlocks: 200000 SecondsPerBlock: 15 MemPoolSize: 50000 StandbyCommittee: diff --git a/pkg/config/protocol_config.go b/pkg/config/protocol_config.go index cddf69bd5..201b97eb1 100644 --- a/pkg/config/protocol_config.go +++ b/pkg/config/protocol_config.go @@ -9,6 +9,8 @@ type ( ProtocolConfiguration struct { Magic netmode.Magic `yaml:"Magic"` MemPoolSize int `yaml:"MemPoolSize"` + // MaxTraceableBlocks is the length of the chain accessible to smart contracts. + MaxTraceableBlocks uint32 `yaml:"MaxTraceableBlocks"` // P2PSigExtensions enables additional signature-related transaction attributes P2PSigExtensions bool `yaml:"P2PSigExtensions"` // ReservedAttributes allows to have reserved attributes range for experimental or private purposes. diff --git a/pkg/core/blockchain.go b/pkg/core/blockchain.go index 84d2de535..2f8a8d0cf 100644 --- a/pkg/core/blockchain.go +++ b/pkg/core/blockchain.go @@ -40,8 +40,9 @@ const ( headerBatchCount = 2000 version = "0.1.0" - defaultMemPoolSize = 50000 - verificationGasLimit = 100000000 // 1 GAS + defaultMemPoolSize = 50000 + defaultMaxTraceableBlocks = 2102400 // 1 year of 15s blocks + verificationGasLimit = 100000000 // 1 GAS ) var ( @@ -148,6 +149,10 @@ func NewBlockchain(s storage.Store, cfg config.ProtocolConfiguration, log *zap.L cfg.MemPoolSize = defaultMemPoolSize log.Info("mempool size is not set or wrong, setting default value", zap.Int("MemPoolSize", cfg.MemPoolSize)) } + if cfg.MaxTraceableBlocks == 0 { + cfg.MaxTraceableBlocks = defaultMaxTraceableBlocks + log.Info("MaxTraceableBlocks is not set or wrong, using default value", zap.Uint32("MaxTraceableBlocks", cfg.MaxTraceableBlocks)) + } committee, err := committeeFromConfig(cfg) if err != nil { return nil, err diff --git a/pkg/core/interop_system.go b/pkg/core/interop_system.go index 509d76344..76cd9dc4c 100644 --- a/pkg/core/interop_system.go +++ b/pkg/core/interop_system.go @@ -26,9 +26,6 @@ const ( // MaxStorageValueLen is the maximum length of a value for storage items. // It is set to be the maximum value for uint16. MaxStorageValueLen = 65535 - // MaxTraceableBlocks is the maximum number of blocks before current chain - // height we're able to give information about. - MaxTraceableBlocks = transaction.MaxValidUntilBlockIncrement // MaxEventNameLen is the maximum length of a name for event. MaxEventNameLen = 32 // MaxNotificationSize is the maximum length of a runtime log message. @@ -155,6 +152,7 @@ func getTransactionAndHeight(cd *dao.Cached, v *vm.VM) (*transaction.Transaction // the block with index specified. func isTraceableBlock(ic *interop.Context, index uint32) bool { height := ic.Chain.BlockHeight() + MaxTraceableBlocks := ic.Chain.GetConfig().MaxTraceableBlocks return index <= height && index+MaxTraceableBlocks > height }