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