From 8de03321079f99269842ecd3937152ccd4b94bba Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Tue, 16 Jun 2020 14:59:09 +0300 Subject: [PATCH] *: use MaxTransactionsPerBlock from Policy native contract part of #904 1. We now have MaxTransactionsPerBlock set in native Policy contract, so this value should be used in (dbft).GetVerified method instead of passing it as an argument. 2. Removed (dbft).WithTxPerBlock. 2. DBFT API has changed, so update it's version. 3. Removed MaxTransactionsPerBlock from node configuration, as we have it set in native Policy contract. --- config/protocol.mainnet.yml | 1 - config/protocol.testnet.yml | 1 - go.mod | 2 +- go.sum | 4 ++-- pkg/config/protocol_config.go | 5 ++--- pkg/consensus/consensus.go | 3 +-- pkg/consensus/consensus_test.go | 6 +++--- pkg/core/blockchain.go | 4 ---- 8 files changed, 9 insertions(+), 17 deletions(-) diff --git a/config/protocol.mainnet.yml b/config/protocol.mainnet.yml index c71bc54c9..1b4e8bada 100644 --- a/config/protocol.mainnet.yml +++ b/config/protocol.mainnet.yml @@ -18,7 +18,6 @@ ProtocolConfiguration: - seed5.neo.org:10333 VerifyBlocks: true VerifyTransactions: false - MaxTransactionsPerBlock: 500 ApplicationConfiguration: # LogPath could be set up in case you need stdout logs to some proper file. diff --git a/config/protocol.testnet.yml b/config/protocol.testnet.yml index 36d7c46ab..2a9c152b3 100644 --- a/config/protocol.testnet.yml +++ b/config/protocol.testnet.yml @@ -18,7 +18,6 @@ ProtocolConfiguration: - seed5t.neo.org:20333 VerifyBlocks: true VerifyTransactions: false - MaxTransactionsPerBlock: 500 ApplicationConfiguration: # LogPath could be set up in case you need stdout logs to some proper file. diff --git a/go.mod b/go.mod index cc7bd8255..de9fc5226 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,7 @@ require ( github.com/go-yaml/yaml v2.1.0+incompatible github.com/gorilla/websocket v1.4.2 github.com/mr-tron/base58 v1.1.2 - github.com/nspcc-dev/dbft v0.0.0-20200531081613-7a39e7b757ac + github.com/nspcc-dev/dbft v0.0.0-20200623100921-5a182c20965e github.com/nspcc-dev/rfc6979 v0.2.0 github.com/pierrec/lz4 v2.5.2+incompatible github.com/pkg/errors v0.8.1 diff --git a/go.sum b/go.sum index f00239b2e..4950195d0 100644 --- a/go.sum +++ b/go.sum @@ -137,8 +137,8 @@ github.com/nspcc-dev/dbft v0.0.0-20200117124306-478e5cfbf03a h1:ajvxgEe9qY4vvoSm github.com/nspcc-dev/dbft v0.0.0-20200117124306-478e5cfbf03a/go.mod h1:/YFK+XOxxg0Bfm6P92lY5eDSLYfp06XOdL8KAVgXjVk= github.com/nspcc-dev/dbft v0.0.0-20200219114139-199d286ed6c1 h1:yEx9WznS+rjE0jl0dLujCxuZSIb+UTjF+005TJu/nNI= github.com/nspcc-dev/dbft v0.0.0-20200219114139-199d286ed6c1/go.mod h1:O0qtn62prQSqizzoagHmuuKoz8QMkU3SzBoKdEvm3aQ= -github.com/nspcc-dev/dbft v0.0.0-20200531081613-7a39e7b757ac h1:cXPgsp4avJ7cR1nPRdpFRHmWoMSRZ41FSvlNjpsyTiA= -github.com/nspcc-dev/dbft v0.0.0-20200531081613-7a39e7b757ac/go.mod h1:1FYQXSbb6/9HQIkoF8XO7W/S8N7AZRkBsgwbcXRvk0E= +github.com/nspcc-dev/dbft v0.0.0-20200623100921-5a182c20965e h1:QOT9slflIkEKb5wY0ZUC0dCmCgoqGlhOAh9+xWMIxfg= +github.com/nspcc-dev/dbft v0.0.0-20200623100921-5a182c20965e/go.mod h1:1FYQXSbb6/9HQIkoF8XO7W/S8N7AZRkBsgwbcXRvk0E= github.com/nspcc-dev/neo-go v0.73.1-pre.0.20200303142215-f5a1b928ce09/go.mod h1:pPYwPZ2ks+uMnlRLUyXOpLieaDQSEaf4NM3zHVbRjmg= github.com/nspcc-dev/neofs-crypto v0.2.0 h1:ftN+59WqxSWz/RCgXYOfhmltOOqU+udsNQSvN6wkFck= github.com/nspcc-dev/neofs-crypto v0.2.0/go.mod h1:F/96fUzPM3wR+UGsPi3faVNmFlA9KAEAUQR7dMxZmNA= diff --git a/pkg/config/protocol_config.go b/pkg/config/protocol_config.go index 293664cdd..eb2dd973f 100644 --- a/pkg/config/protocol_config.go +++ b/pkg/config/protocol_config.go @@ -7,9 +7,8 @@ import ( // ProtocolConfiguration represents the protocol config. type ( ProtocolConfiguration struct { - Magic netmode.Magic `yaml:"Magic"` - MaxTransactionsPerBlock int `yaml:"MaxTransactionsPerBlock"` - MemPoolSize int `yaml:"MemPoolSize"` + Magic netmode.Magic `yaml:"Magic"` + MemPoolSize int `yaml:"MemPoolSize"` // SaveStorageBatch enables storage batch saving before every persist. SaveStorageBatch bool `yaml:"SaveStorageBatch"` SecondsPerBlock int `yaml:"SecondsPerBlock"` diff --git a/pkg/consensus/consensus.go b/pkg/consensus/consensus.go index 289ee5f89..6113753a9 100644 --- a/pkg/consensus/consensus.go +++ b/pkg/consensus/consensus.go @@ -121,7 +121,6 @@ func NewService(cfg Config) (Service, error) { dbft.WithLogger(srv.log), dbft.WithSecondsPerBlock(cfg.TimePerBlock), dbft.WithGetKeyPair(srv.getKeyPair), - dbft.WithTxPerBlock(10000), dbft.WithRequestTx(cfg.RequestTx), dbft.WithGetTx(srv.getTx), dbft.WithGetVerified(srv.getVerifiedTx), @@ -392,7 +391,7 @@ func (s *service) getBlock(h util.Uint256) block.Block { return &neoBlock{Block: *b} } -func (s *service) getVerifiedTx(count int) []block.Transaction { +func (s *service) getVerifiedTx() []block.Transaction { pool := s.Config.Chain.GetMemPool() var txx []*transaction.Transaction diff --git a/pkg/consensus/consensus_test.go b/pkg/consensus/consensus_test.go index 2db405ef2..6ad040cc5 100644 --- a/pkg/consensus/consensus_test.go +++ b/pkg/consensus/consensus_test.go @@ -31,7 +31,7 @@ func TestNewService(t *testing.T) { require.NoError(t, srv.Chain.PoolTx(tx)) var txx []block.Transaction - require.NotPanics(t, func() { txx = srv.getVerifiedTx(1) }) + require.NotPanics(t, func() { txx = srv.getVerifiedTx() }) require.Len(t, txx, 1) require.Equal(t, tx, txx[0]) srv.Chain.Close() @@ -69,7 +69,7 @@ func TestService_GetVerified(t *testing.T) { srv.dbft.ViewNumber = 1 t.Run("new transactions will be proposed in case of failure", func(t *testing.T) { - txx := srv.getVerifiedTx(10) + txx := srv.getVerifiedTx() require.Equal(t, 1, len(txx), "there is only 1 tx in mempool") require.Equal(t, txs[3], txx[0]) }) @@ -79,7 +79,7 @@ func TestService_GetVerified(t *testing.T) { require.NoError(t, srv.Chain.PoolTx(tx)) } - txx := srv.getVerifiedTx(10) + txx := srv.getVerifiedTx() require.Contains(t, txx, txs[0]) require.Contains(t, txx, txs[1]) require.NotContains(t, txx, txs[2]) diff --git a/pkg/core/blockchain.go b/pkg/core/blockchain.go index 8bf5c0fdf..a9658d6e9 100644 --- a/pkg/core/blockchain.go +++ b/pkg/core/blockchain.go @@ -152,10 +152,6 @@ 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.MaxTransactionsPerBlock <= 0 { - cfg.MaxTransactionsPerBlock = 0 - log.Info("MaxTransactionsPerBlock is not set or wrong, setting default value (unlimited)", zap.Int("MaxTransactionsPerBlock", cfg.MaxTransactionsPerBlock)) - } bc := &Blockchain{ config: cfg, dao: dao.NewSimple(s, cfg.Magic),