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 824627863..5aae8f1f9 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/blockchain_test.go b/pkg/core/blockchain_test.go index 49ab65f97..dab65aa4b 100644 --- a/pkg/core/blockchain_test.go +++ b/pkg/core/blockchain_test.go @@ -924,7 +924,7 @@ func TestSubscriptions(t *testing.T) { txGood1 := transaction.New(netmode.UnitTestNet, script.Bytes(), 0) txGood1.Signers = []transaction.Signer{{Account: neoOwner}} txGood1.Nonce = 1 - txGood1.ValidUntilBlock = 100500 + txGood1.ValidUntilBlock = 1024 require.NoError(t, signTx(bc, txGood1)) // Reset() reuses the script buffer and we need to keep scripts. @@ -936,7 +936,7 @@ func TestSubscriptions(t *testing.T) { txBad := transaction.New(netmode.UnitTestNet, script.Bytes(), 0) txBad.Signers = []transaction.Signer{{Account: neoOwner}} txBad.Nonce = 2 - txBad.ValidUntilBlock = 100500 + txBad.ValidUntilBlock = 1024 require.NoError(t, signTx(bc, txBad)) script = io.NewBufBinWriter() @@ -946,7 +946,7 @@ func TestSubscriptions(t *testing.T) { txGood2 := transaction.New(netmode.UnitTestNet, script.Bytes(), 0) txGood2.Signers = []transaction.Signer{{Account: neoOwner}} txGood2.Nonce = 3 - txGood2.ValidUntilBlock = 100500 + txGood2.ValidUntilBlock = 1024 require.NoError(t, signTx(bc, txGood2)) invBlock := newBlock(bc.config, bc.BlockHeight()+1, bc.CurrentHeaderHash(), txGood1, txBad, txGood2) 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 } diff --git a/pkg/core/transaction/oracle.go b/pkg/core/transaction/oracle.go index 67c16fb83..0477373d5 100644 --- a/pkg/core/transaction/oracle.go +++ b/pkg/core/transaction/oracle.go @@ -2,6 +2,7 @@ package transaction import ( "errors" + "math" "github.com/nspcc-dev/neo-go/pkg/io" ) @@ -16,7 +17,8 @@ type OracleResponse struct { Result []byte `json:"result"` } -const maxResultSize = 1024 +// MaxOracleResultSize is the maximum allowed oracle answer size. +const MaxOracleResultSize = math.MaxUint16 // Enumeration of possible oracle response types. const ( @@ -46,7 +48,7 @@ func (r *OracleResponse) DecodeBinary(br *io.BinReader) { br.Err = ErrInvalidResponseCode return } - r.Result = br.ReadVarBytes(maxResultSize) + r.Result = br.ReadVarBytes(MaxOracleResultSize) if r.Code != Success && len(r.Result) > 0 { br.Err = ErrInvalidResult } diff --git a/pkg/core/transaction/transaction.go b/pkg/core/transaction/transaction.go index dc1d9abe5..1b82981ec 100644 --- a/pkg/core/transaction/transaction.go +++ b/pkg/core/transaction/transaction.go @@ -20,9 +20,10 @@ const ( // MaxTransactionSize is the upper limit size in bytes that a transaction can reach. It is // set to be 102400. MaxTransactionSize = 102400 - // MaxValidUntilBlockIncrement is the upper increment size of blockhain height in blocs after - // exceeding that a transaction should fail validation. It is set to be 2102400. - MaxValidUntilBlockIncrement = 2102400 + // MaxValidUntilBlockIncrement is the upper increment size of blockhain height in blocks + // exceeding that a transaction should fail validation. It is set to estimated daily number + // of blocks with 15s interval. + MaxValidUntilBlockIncrement = 5760 // MaxAttributes is maximum number of attributes including signers that can be contained // within a transaction. It is set to be 16. MaxAttributes = 16