Added check for circular and out-of-range dependency problem (#841)

* added check for circular and out-of-range dependency problem

* addressed comment

* addressed comments
This commit is contained in:
Pratik Patil 2023-05-11 12:20:58 +05:30 committed by GitHub
parent adce0e8235
commit c39c66fb9c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -290,6 +290,11 @@ func (p *ParallelStateProcessor) Process(block *types.Block, statedb *state.Stat
if block.Header().TxDependency != nil { if block.Header().TxDependency != nil {
metadata = true metadata = true
if !VerifyDeps(deps) {
metadata = false
deps = GetDeps([][]uint64{})
}
} }
blockContext := NewEVMBlockContext(header, p.bc, nil) blockContext := NewEVMBlockContext(header, p.bc, nil)
@ -431,3 +436,20 @@ func GetDeps(txDependency [][]uint64) map[int][]int {
return deps return deps
} }
// returns true if dependencies are correct
func VerifyDeps(deps map[int][]int) bool {
// number of transactions in the block
n := len(deps)
// Handle out-of-range and circular dependency problem
for tx, val := range deps {
for depTx := range val {
if depTx >= n || depTx < tx {
return false
}
}
}
return true
}