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"` StandbyValidators []string `yaml:"StandbyValidators"`
SeedList []string `yaml:"SeedList"` SeedList []string `yaml:"SeedList"`
SystemFee SystemFee `yaml:"SystemFee"` 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. // SystemFee fees related to system.

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -68,9 +68,6 @@ type Blockchain struct {
headersOp chan headersOpFunc headersOp chan headersOpFunc
headersOpDone chan struct{} headersOpDone chan struct{}
// Whether we will verify received blocks.
verifyBlocks bool
memPool MemPool memPool MemPool
} }
@ -85,7 +82,6 @@ func NewBlockchain(s storage.Store, cfg config.ProtocolConfiguration) (*Blockcha
memStore: storage.NewMemoryStore(), memStore: storage.NewMemoryStore(),
headersOp: make(chan headersOpFunc), headersOp: make(chan headersOpFunc),
headersOpDone: make(chan struct{}), headersOpDone: make(chan struct{}),
verifyBlocks: false,
memPool: NewMemPool(50000), memPool: NewMemPool(50000),
} }
@ -209,15 +205,17 @@ func (bc *Blockchain) AddBlock(block *Block) error {
if expectedHeight != block.Index { if expectedHeight != block.Index {
return fmt.Errorf("expected block %d, but passed block %d", 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) err := block.Verify(false)
if err != nil { if err != nil {
return fmt.Errorf("block %s is invalid: %s", block.Hash().ReverseString(), err) return fmt.Errorf("block %s is invalid: %s", block.Hash().ReverseString(), err)
} }
for _, tx := range block.Transactions { if bc.config.VerifyTransactions {
err := bc.VerifyTx(tx, block) for _, tx := range block.Transactions {
if err != nil { err := bc.VerifyTx(tx, block)
return fmt.Errorf("transaction %s failed to verify: %s", tx.Hash().ReverseString(), err) if err != nil {
return fmt.Errorf("transaction %s failed to verify: %s", tx.Hash().ReverseString(), err)
}
} }
} }
} }