Optimized the dependency metadata structure (#804)

* removed the first 2 element in TxDependency[i]

* addressed comments
This commit is contained in:
Pratik Patil 2023-04-05 11:12:57 +05:30 committed by GitHub
parent 55962e16c6
commit 480ccf2aa8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 25 additions and 36 deletions

View file

@ -297,7 +297,7 @@ func (p *ParallelStateProcessor) Process(block *types.Block, statedb *state.Stat
coinbase, _ := p.bc.Engine().Author(header)
deps, delayMap := GetDeps(block.Header().TxDependency)
deps := GetDeps(block.Header().TxDependency)
if block.Header().TxDependency != nil {
metadata = true
@ -315,9 +315,11 @@ func (p *ParallelStateProcessor) Process(block *types.Block, statedb *state.Stat
cleansdb := statedb.Copy()
if len(header.TxDependency) > 0 {
shouldDelayFeeCal = delayMap[i]
if msg.From() == coinbase {
shouldDelayFeeCal = false
}
if len(header.TxDependency) != len(block.Transactions()) {
task := &ExecutionTask{
msg: msg,
config: p.config,
@ -343,10 +345,6 @@ func (p *ParallelStateProcessor) Process(block *types.Block, statedb *state.Stat
tasks = append(tasks, task)
} else {
if msg.From() == coinbase {
shouldDelayFeeCal = false
}
task := &ExecutionTask{
msg: msg,
config: p.config,
@ -430,22 +428,16 @@ func (p *ParallelStateProcessor) Process(block *types.Block, statedb *state.Stat
return receipts, allLogs, *usedGas, nil
}
func GetDeps(txDependency [][]uint64) (map[int][]int, map[int]bool) {
func GetDeps(txDependency [][]uint64) map[int][]int {
deps := make(map[int][]int)
delayMap := make(map[int]bool)
for i := 0; i <= len(txDependency)-1; i++ {
idx := int(txDependency[i][0])
shouldDelay := txDependency[i][1] == 1
deps[i] = []int{}
delayMap[idx] = shouldDelay
deps[idx] = []int{}
for j := 2; j <= len(txDependency[i])-1; j++ {
deps[idx] = append(deps[idx], int(txDependency[i][j]))
for j := 0; j <= len(txDependency[i])-1; j++ {
deps[i] = append(deps[i], int(txDependency[i][j]))
}
}
return deps, delayMap
return deps
}

View file

@ -87,11 +87,9 @@ type Header struct {
// BaseFee was added by EIP-1559 and is ignored in legacy headers.
BaseFee *big.Int `json:"baseFeePerGas" rlp:"optional"`
// length of TxDependency -> n (n = number of transactions in the block)
// length of TxDependency[i] -> 2 + k (k = a whole number)
// first 2 element in TxDependency[i] -> transaction index, and flag representing if delay is allowed or not
// (0 -> delay is not allowed, 1 -> delay is allowed)
// next k elements in TxDependency[i] -> transaction indexes on which transaction i is dependent on
// length of TxDependency -> n (n = number of transactions in the block)
// length of TxDependency[i] -> k (k = a whole number)
// k elements in TxDependency[i] -> transaction indexes on which transaction i is dependent on
TxDependency [][]uint64 `json:"txDependency" rlp:"optional"`
/*

View file

@ -1133,28 +1133,20 @@ func (w *worker) commitTransactions(env *environment, txs *types.TransactionsByP
if len(mvReadMapList) > 0 {
tempDeps := make([][]uint64, len(mvReadMapList))
// adding for txIdx = 0
tempDeps[0] = []uint64{uint64(0)}
tempDeps[0] = append(tempDeps[0], 1)
for j := range deps[0] {
tempDeps[0] = append(tempDeps[0], uint64(j))
}
for i := 1; i <= len(mvReadMapList)-1; i++ {
tempDeps[i] = []uint64{uint64(i)}
delayFlag := true
for i := 1; i <= len(mvReadMapList)-1; i++ {
reads := mvReadMapList[i-1]
_, ok1 := reads[blockstm.NewSubpathKey(env.coinbase, state.BalancePath)]
_, ok2 := reads[blockstm.NewSubpathKey(common.HexToAddress(w.chainConfig.Bor.CalculateBurntContract(env.header.Number.Uint64())), state.BalancePath)]
if ok1 || ok2 {
// 0 -> delay is not allowed
tempDeps[i] = append(tempDeps[i], 0)
} else {
// 1 -> delay is allowed
tempDeps[i] = append(tempDeps[i], 1)
delayFlag = false
}
for j := range deps[i] {
@ -1162,7 +1154,11 @@ func (w *worker) commitTransactions(env *environment, txs *types.TransactionsByP
}
}
env.header.TxDependency = tempDeps
if delayFlag {
env.header.TxDependency = tempDeps
} else {
env.header.TxDependency = nil
}
} else {
env.header.TxDependency = nil
}

View file

@ -819,8 +819,11 @@ func BenchmarkBorMiningBlockSTMMetadata(b *testing.B) {
}
} else {
deps := block.TxDependency()
if len(deps[0]) != 0 {
b.Fatalf("wrong dependency")
}
for i := 1; i < block.Transactions().Len(); i++ {
if deps[i][0] != uint64(i) || deps[i][1] != uint64(0) || deps[i][2] != uint64(i-1) || len(deps[i]) != 3 {
if deps[i][0] != uint64(i-1) || len(deps[i]) != 1 {
b.Fatalf("wrong dependency")
}
}