go-ethereum/core/blockstm/txio.go
Pratik Patil d53c2e7902
Block stm miner dependency (#561)
* added support for dependencies (executor_tests)

* added a function to get dependency map

* getting all dependencies in the GetDep function

* updated GetDep function

* changed the type of AllDeps

* added a function to get dependency map

* updated GetDep function

* generate and get dependencies from block producer

* optimized getDep function

* bug fix regarding txn index and dep structure

* fixed gas bug

* optimized getDep function

* tests updated/added

* few updates regarding dependencies

* added channel to calculate the dependencies in a separate go routine

* minor changes in the executor which uses latest changes of dependecies + removed metadata flag/argument

* Use channel when metadata is available

* small bug fix

* getting reads and writes only when the transaction succeeds

* fixed bug in adding dependencies

* updated logic for delay/not delay

* bug fix (shouldDelayFeeCal) in parallel state processor

* lint fix

* using EnableMVHashMap flag

* fixed worker and stateProcessor and removed SetMVHashMapNil fumction from stateDB

* addredded few comments and fixed bug in executor tests

* commented executor tests with metadata (panic: test timed out after 5m0s)

* added a check to check len(mvReadMapList) > 0 in miner

* addressed comments, minor refactoring in dag.go

* moved blockContext out of Execute and adding it in execution task

* removed Author() from Settle() and added  in execution task

* not calling block.Header() again and again, using  instead

* removed EnableMVHashMap flag, and updated applyTransaction function

* addressed comments

* added unit test to check dependencies in the block header

Co-authored-by: Jerry <jerrycgh@gmail.com>
2022-12-23 09:14:09 +05:30

94 lines
2 KiB
Go

package blockstm
const (
ReadKindMap = 0
ReadKindStorage = 1
)
type ReadDescriptor struct {
Path Key
Kind int
V Version
}
type WriteDescriptor struct {
Path Key
V Version
Val interface{}
}
type TxnInput []ReadDescriptor
type TxnOutput []WriteDescriptor
// hasNewWrite: returns true if the current set has a new write compared to the input
func (txo TxnOutput) hasNewWrite(cmpSet []WriteDescriptor) bool {
if len(txo) == 0 {
return false
} else if len(cmpSet) == 0 || len(txo) > len(cmpSet) {
return true
}
cmpMap := map[Key]bool{cmpSet[0].Path: true}
for i := 1; i < len(cmpSet); i++ {
cmpMap[cmpSet[i].Path] = true
}
for _, v := range txo {
if !cmpMap[v.Path] {
return true
}
}
return false
}
type TxnInputOutput struct {
inputs []TxnInput
outputs []TxnOutput // write sets that should be checked during validation
allOutputs []TxnOutput // entire write sets in MVHashMap. allOutputs should always be a parent set of outputs
}
func (io *TxnInputOutput) ReadSet(txnIdx int) []ReadDescriptor {
return io.inputs[txnIdx]
}
func (io *TxnInputOutput) WriteSet(txnIdx int) []WriteDescriptor {
return io.outputs[txnIdx]
}
func (io *TxnInputOutput) AllWriteSet(txnIdx int) []WriteDescriptor {
return io.allOutputs[txnIdx]
}
func MakeTxnInputOutput(numTx int) *TxnInputOutput {
return &TxnInputOutput{
inputs: make([]TxnInput, numTx),
outputs: make([]TxnOutput, numTx),
allOutputs: make([]TxnOutput, numTx),
}
}
func (io *TxnInputOutput) recordRead(txId int, input []ReadDescriptor) {
io.inputs[txId] = input
}
func (io *TxnInputOutput) recordWrite(txId int, output []WriteDescriptor) {
io.outputs[txId] = output
}
func (io *TxnInputOutput) recordAllWrite(txId int, output []WriteDescriptor) {
io.allOutputs[txId] = output
}
func (io *TxnInputOutput) RecordReadAtOnce(inputs [][]ReadDescriptor) {
for ind, val := range inputs {
io.inputs[ind] = val
}
}
func (io *TxnInputOutput) RecordAllWriteAtOnce(outputs [][]WriteDescriptor) {
for ind, val := range outputs {
io.allOutputs[ind] = val
}
}