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:
parent
56dcff2894
commit
aec6a5f029
10 changed files with 27 additions and 9 deletions
|
@ -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.
|
||||
|
|
|
@ -27,6 +27,8 @@ ProtocolConfiguration:
|
|||
IssueTransaction: 500
|
||||
PublishTransaction: 500
|
||||
RegisterTransaction: 10000
|
||||
VerifyBlocks: true
|
||||
VerifyTransactions: false
|
||||
|
||||
ApplicationConfiguration:
|
||||
DBConfiguration:
|
||||
|
|
|
@ -15,6 +15,8 @@ ProtocolConfiguration:
|
|||
IssueTransaction: 500
|
||||
PublishTransaction: 500
|
||||
RegisterTransaction: 10000
|
||||
VerifyBlocks: true
|
||||
VerifyTransactions: true
|
||||
|
||||
ApplicationConfiguration:
|
||||
DBConfiguration:
|
||||
|
|
|
@ -12,6 +12,8 @@ ProtocolConfiguration:
|
|||
IssueTransaction: 500
|
||||
PublishTransaction: 500
|
||||
RegisterTransaction: 10000
|
||||
VerifyBlocks: true
|
||||
VerifyTransactions: true
|
||||
|
||||
ApplicationConfiguration:
|
||||
DBConfiguration:
|
||||
|
|
|
@ -12,6 +12,8 @@ ProtocolConfiguration:
|
|||
IssueTransaction: 500
|
||||
PublishTransaction: 500
|
||||
RegisterTransaction: 10000
|
||||
VerifyBlocks: true
|
||||
VerifyTransactions: true
|
||||
|
||||
ApplicationConfiguration:
|
||||
DBConfiguration:
|
||||
|
|
|
@ -12,6 +12,8 @@ ProtocolConfiguration:
|
|||
IssueTransaction: 500
|
||||
PublishTransaction: 500
|
||||
RegisterTransaction: 10000
|
||||
VerifyBlocks: true
|
||||
VerifyTransactions: true
|
||||
|
||||
ApplicationConfiguration:
|
||||
DBConfiguration:
|
||||
|
|
|
@ -18,6 +18,8 @@ ProtocolConfiguration:
|
|||
IssueTransaction: 500
|
||||
PublishTransaction: 500
|
||||
RegisterTransaction: 10000
|
||||
VerifyBlocks: true
|
||||
VerifyTransactions: true
|
||||
|
||||
ApplicationConfiguration:
|
||||
DBConfiguration:
|
||||
|
|
|
@ -27,6 +27,8 @@ ProtocolConfiguration:
|
|||
IssueTransaction: 5
|
||||
PublishTransaction: 5
|
||||
RegisterTransaction: 100
|
||||
VerifyBlocks: true
|
||||
VerifyTransactions: false
|
||||
|
||||
ApplicationConfiguration:
|
||||
DBConfiguration:
|
||||
|
|
|
@ -17,6 +17,8 @@ ProtocolConfiguration:
|
|||
IssueTransaction: 500
|
||||
PublishTransaction: 500
|
||||
RegisterTransaction: 10000
|
||||
VerifyBlocks: true
|
||||
VerifyTransactions: true
|
||||
|
||||
ApplicationConfiguration:
|
||||
DBConfiguration:
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue