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.
This commit is contained in:
Roman Khimov 2019-10-11 17:46:47 +03:00
parent 56dcff2894
commit aec6a5f029
10 changed files with 27 additions and 9 deletions

View file

@ -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.

View file

@ -27,6 +27,8 @@ ProtocolConfiguration:
IssueTransaction: 500
PublishTransaction: 500
RegisterTransaction: 10000
VerifyBlocks: true
VerifyTransactions: false
ApplicationConfiguration:
DBConfiguration:

View file

@ -15,6 +15,8 @@ ProtocolConfiguration:
IssueTransaction: 500
PublishTransaction: 500
RegisterTransaction: 10000
VerifyBlocks: true
VerifyTransactions: true
ApplicationConfiguration:
DBConfiguration:

View file

@ -12,6 +12,8 @@ ProtocolConfiguration:
IssueTransaction: 500
PublishTransaction: 500
RegisterTransaction: 10000
VerifyBlocks: true
VerifyTransactions: true
ApplicationConfiguration:
DBConfiguration:

View file

@ -12,6 +12,8 @@ ProtocolConfiguration:
IssueTransaction: 500
PublishTransaction: 500
RegisterTransaction: 10000
VerifyBlocks: true
VerifyTransactions: true
ApplicationConfiguration:
DBConfiguration:

View file

@ -12,6 +12,8 @@ ProtocolConfiguration:
IssueTransaction: 500
PublishTransaction: 500
RegisterTransaction: 10000
VerifyBlocks: true
VerifyTransactions: true
ApplicationConfiguration:
DBConfiguration:

View file

@ -18,6 +18,8 @@ ProtocolConfiguration:
IssueTransaction: 500
PublishTransaction: 500
RegisterTransaction: 10000
VerifyBlocks: true
VerifyTransactions: true
ApplicationConfiguration:
DBConfiguration:

View file

@ -27,6 +27,8 @@ ProtocolConfiguration:
IssueTransaction: 5
PublishTransaction: 5
RegisterTransaction: 100
VerifyBlocks: true
VerifyTransactions: false
ApplicationConfiguration:
DBConfiguration:

View file

@ -17,6 +17,8 @@ ProtocolConfiguration:
IssueTransaction: 500
PublishTransaction: 500
RegisterTransaction: 10000
VerifyBlocks: true
VerifyTransactions: true
ApplicationConfiguration:
DBConfiguration:

View file

@ -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,11 +205,12 @@ 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)
}
if bc.config.VerifyTransactions {
for _, tx := range block.Transactions {
err := bc.VerifyTx(tx, block)
if err != nil {
@ -221,6 +218,7 @@ func (bc *Blockchain) AddBlock(block *Block) error {
}
}
}
}
headerLen := bc.headerListLen()
if int(block.Index) == headerLen {
err := bc.AddHeaders(block.Header())