From aec6a5f029c10e2868bfd95d32e799e3e4f9ed33 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Fri, 11 Oct 2019 17:46:47 +0300 Subject: [PATCH] core/config: make block and transaction verification configurable Enable transaction verification for privnets and tests, testnet can't successfuly verify block number 316711 with it enabled and mainnet stops at 105829. --- config/config.go | 4 ++++ config/protocol.mainnet.yml | 2 ++ config/protocol.privnet.docker.four.yml | 2 ++ config/protocol.privnet.docker.one.yml | 2 ++ config/protocol.privnet.docker.three.yml | 2 ++ config/protocol.privnet.docker.two.yml | 2 ++ config/protocol.privnet.yml | 2 ++ config/protocol.testnet.yml | 2 ++ config/protocol.unit_testnet.yml | 2 ++ pkg/core/blockchain.go | 16 +++++++--------- 10 files changed, 27 insertions(+), 9 deletions(-) diff --git a/config/config.go b/config/config.go index 16673f5b7..d63c9f1d6 100644 --- a/config/config.go +++ b/config/config.go @@ -49,6 +49,10 @@ type ( StandbyValidators []string `yaml:"StandbyValidators"` SeedList []string `yaml:"SeedList"` SystemFee SystemFee `yaml:"SystemFee"` + // Whether to verify received blocks. + VerifyBlocks bool `yaml:"VerifyBlocks"` + // Whether to verify transactions in received blocks. + VerifyTransactions bool `yaml:"VerifyTransactions"` } // SystemFee fees related to system. diff --git a/config/protocol.mainnet.yml b/config/protocol.mainnet.yml index 6292ffe58..87805be90 100644 --- a/config/protocol.mainnet.yml +++ b/config/protocol.mainnet.yml @@ -27,6 +27,8 @@ ProtocolConfiguration: IssueTransaction: 500 PublishTransaction: 500 RegisterTransaction: 10000 + VerifyBlocks: true + VerifyTransactions: false ApplicationConfiguration: DBConfiguration: diff --git a/config/protocol.privnet.docker.four.yml b/config/protocol.privnet.docker.four.yml index d530183ff..b18ac83cd 100644 --- a/config/protocol.privnet.docker.four.yml +++ b/config/protocol.privnet.docker.four.yml @@ -15,6 +15,8 @@ ProtocolConfiguration: IssueTransaction: 500 PublishTransaction: 500 RegisterTransaction: 10000 + VerifyBlocks: true + VerifyTransactions: true ApplicationConfiguration: DBConfiguration: diff --git a/config/protocol.privnet.docker.one.yml b/config/protocol.privnet.docker.one.yml index 96e88f07a..2637c6635 100644 --- a/config/protocol.privnet.docker.one.yml +++ b/config/protocol.privnet.docker.one.yml @@ -12,6 +12,8 @@ ProtocolConfiguration: IssueTransaction: 500 PublishTransaction: 500 RegisterTransaction: 10000 + VerifyBlocks: true + VerifyTransactions: true ApplicationConfiguration: DBConfiguration: diff --git a/config/protocol.privnet.docker.three.yml b/config/protocol.privnet.docker.three.yml index 82206637c..c2f3e237b 100644 --- a/config/protocol.privnet.docker.three.yml +++ b/config/protocol.privnet.docker.three.yml @@ -12,6 +12,8 @@ ProtocolConfiguration: IssueTransaction: 500 PublishTransaction: 500 RegisterTransaction: 10000 + VerifyBlocks: true + VerifyTransactions: true ApplicationConfiguration: DBConfiguration: diff --git a/config/protocol.privnet.docker.two.yml b/config/protocol.privnet.docker.two.yml index 422e452ed..3f8a2b929 100644 --- a/config/protocol.privnet.docker.two.yml +++ b/config/protocol.privnet.docker.two.yml @@ -12,6 +12,8 @@ ProtocolConfiguration: IssueTransaction: 500 PublishTransaction: 500 RegisterTransaction: 10000 + VerifyBlocks: true + VerifyTransactions: true ApplicationConfiguration: DBConfiguration: diff --git a/config/protocol.privnet.yml b/config/protocol.privnet.yml index 9e28b12d6..2a31395fc 100644 --- a/config/protocol.privnet.yml +++ b/config/protocol.privnet.yml @@ -18,6 +18,8 @@ ProtocolConfiguration: IssueTransaction: 500 PublishTransaction: 500 RegisterTransaction: 10000 + VerifyBlocks: true + VerifyTransactions: true ApplicationConfiguration: DBConfiguration: diff --git a/config/protocol.testnet.yml b/config/protocol.testnet.yml index 13b33a90d..7e3f2e332 100644 --- a/config/protocol.testnet.yml +++ b/config/protocol.testnet.yml @@ -27,6 +27,8 @@ ProtocolConfiguration: IssueTransaction: 5 PublishTransaction: 5 RegisterTransaction: 100 + VerifyBlocks: true + VerifyTransactions: false ApplicationConfiguration: DBConfiguration: diff --git a/config/protocol.unit_testnet.yml b/config/protocol.unit_testnet.yml index eb3490e85..1bf522cb3 100644 --- a/config/protocol.unit_testnet.yml +++ b/config/protocol.unit_testnet.yml @@ -17,6 +17,8 @@ ProtocolConfiguration: IssueTransaction: 500 PublishTransaction: 500 RegisterTransaction: 10000 + VerifyBlocks: true + VerifyTransactions: true ApplicationConfiguration: DBConfiguration: diff --git a/pkg/core/blockchain.go b/pkg/core/blockchain.go index 671b46871..d286e425e 100644 --- a/pkg/core/blockchain.go +++ b/pkg/core/blockchain.go @@ -68,9 +68,6 @@ type Blockchain struct { headersOp chan headersOpFunc headersOpDone chan struct{} - // Whether we will verify received blocks. - verifyBlocks bool - memPool MemPool } @@ -85,7 +82,6 @@ func NewBlockchain(s storage.Store, cfg config.ProtocolConfiguration) (*Blockcha memStore: storage.NewMemoryStore(), headersOp: make(chan headersOpFunc), headersOpDone: make(chan struct{}), - verifyBlocks: false, memPool: NewMemPool(50000), } @@ -209,15 +205,17 @@ func (bc *Blockchain) AddBlock(block *Block) error { if expectedHeight != block.Index { return fmt.Errorf("expected block %d, but passed block %d", expectedHeight, block.Index) } - if bc.verifyBlocks { + if bc.config.VerifyBlocks { err := block.Verify(false) if err != nil { return fmt.Errorf("block %s is invalid: %s", block.Hash().ReverseString(), err) } - for _, tx := range block.Transactions { - err := bc.VerifyTx(tx, block) - if err != nil { - return fmt.Errorf("transaction %s failed to verify: %s", tx.Hash().ReverseString(), err) + if bc.config.VerifyTransactions { + for _, tx := range block.Transactions { + err := bc.VerifyTx(tx, block) + if err != nil { + return fmt.Errorf("transaction %s failed to verify: %s", tx.Hash().ReverseString(), err) + } } } }