Sokol v0: support for first epoch-set transition (#2411)

This commit is contained in:
Alex Sharov 2021-07-21 18:13:26 +07:00 committed by GitHub
parent 33b122424c
commit d2552196ad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
25 changed files with 865 additions and 396 deletions

View File

@ -15,6 +15,7 @@ linters:
- unused
- varcheck
- gocritic
# - forcetypeassert
linters-settings:
gocritic:

View File

@ -2257,7 +2257,7 @@ func runBlock(ibs *state.IntraBlockState, txnWriter state.StateWriter, blockWrit
if !vmConfig.ReadOnly {
// Finalize the block, applying any consensus engine specific extras (e.g. block rewards)
if _, err := engine.FinalizeAndAssemble(chainConfig, header, ibs, block.Transactions(), block.Uncles(), receipts, nil, nil); err != nil {
if _, err := engine.FinalizeAndAssemble(chainConfig, header, ibs, block.Transactions(), block.Uncles(), receipts, nil, nil, nil, nil); err != nil {
return nil, fmt.Errorf("finalize of block %d failed: %v", block.NumberU64(), err)
}

View File

@ -138,6 +138,9 @@ func resetExec(tx ethdb.RwTx, g *core.Genesis) error {
if err := tx.(ethdb.BucketMigrator).ClearBucket(dbutils.Epoch); err != nil {
return err
}
if err := tx.(ethdb.BucketMigrator).ClearBucket(dbutils.PendingEpoch); err != nil {
return err
}
if err := stages.SaveStageProgress(tx, stages.Execution, 0); err != nil {
return err
}
@ -247,6 +250,7 @@ func printStages(db ethdb.KVGetter) error {
defer w.Flush()
w.Init(os.Stdout, 8, 8, 0, '\t', 0)
fmt.Fprintf(w, "Note: prune_at doesn't mean 'all data before were deleted' - it just mean stage.Prune function were run to this block. Because 1 stage may prune multiple data types to different prune distance.\n")
fmt.Fprint(w, "\n \t stage_at \t prune_at\n")
for _, stage := range stages.AllStages {
if progress, err = stages.GetStageProgress(db, stage); err != nil {
return err
@ -255,13 +259,13 @@ func printStages(db ethdb.KVGetter) error {
if err != nil {
return err
}
fmt.Fprintf(w, "%s \t %d \t prune_at=%d\n", string(stage), progress, prunedTo)
fmt.Fprintf(w, "%s \t %d \t %d\n", string(stage), progress, prunedTo)
}
pm, err := prune.Get(db)
if err != nil {
return err
}
fmt.Fprintf(w, "--\n")
fmt.Fprintf(w, "prune distance: %#v\n", pm)
fmt.Fprintf(w, "prune distance: %s\n\n", pm.ToString())
return nil
}

View File

@ -156,6 +156,9 @@ func syncBySmallSteps(db ethdb.RwKV, miningConfig params.MiningConfig, ctx conte
expectedAccountChanges := make(map[uint64]*changeset.ChangeSet)
expectedStorageChanges := make(map[uint64]*changeset.ChangeSet)
changeSetHook := func(blockNum uint64, csw *state.ChangeSetWriter) {
if csw == nil {
return
}
accountChanges, err := csw.GetAccountChanges()
if err != nil {
panic(err)

View File

@ -120,7 +120,7 @@ func TestMatreshkaStream(t *testing.T) {
checkTEVM := ethdb.GetCheckTEVM(tx)
_, err = core.ExecuteBlockEphemerally(chainConfig, &vm.Config{NoReceipts: true}, getHeader, ethash.NewFaker(), block, stateReaderWriter, stateReaderWriter, nil, checkTEVM)
_, err = core.ExecuteBlockEphemerally(chainConfig, &vm.Config{NoReceipts: true}, getHeader, ethash.NewFaker(), block, stateReaderWriter, stateReaderWriter, nil, nil, checkTEVM)
if err != nil {
t.Fatal(err, currentBlock)
}

View File

@ -686,7 +686,7 @@ func runBlock(ibs *state.IntraBlockState, txnWriter state.StateWriter, blockWrit
if !vmConfig.ReadOnly {
// Finalize the block, applying any consensus engine specific extras (e.g. block rewards)
if _, err := engine.FinalizeAndAssemble(chainConfig, header, ibs, block.Transactions(), block.Uncles(), receipts, nil, nil); err != nil {
if _, err := engine.FinalizeAndAssemble(chainConfig, header, ibs, block.Transactions(), block.Uncles(), receipts, nil, nil, nil, nil); err != nil {
return nil, fmt.Errorf("finalize of block %d failed: %v", block.NumberU64(), err)
}

View File

@ -279,6 +279,7 @@ const (
HeadHeaderKey = "LastHeader"
Epoch = "DevEpoch" // block_num_u64+block_hash->transition_proof
PendingEpoch = "DevPendingEpoch" // block_num_u64+block_hash->transition_proof
)
// Keys
@ -348,6 +349,7 @@ var Buckets = []string{
HeadersBucket,
HeaderTDBucket,
Epoch,
PendingEpoch,
}
// DeprecatedBuckets - list of buckets which can be programmatically deleted - for example after migration

View File

@ -131,7 +131,7 @@ func (c *Collector) Close(logPrefix string) {
totalSize += p.Dispose()
}
if totalSize > 0 {
log.Info(fmt.Sprintf("[%s] etl: temp files removed successfully", logPrefix), "total size", datasize.ByteSize(totalSize).HumanReadable())
log.Info(fmt.Sprintf("[%s] etl: temp files removed", logPrefix), "total size", datasize.ByteSize(totalSize).HumanReadable())
}
}

File diff suppressed because one or more lines are too long

View File

@ -24,15 +24,16 @@ import (
"github.com/ledgerwatch/erigon/common"
"github.com/ledgerwatch/erigon/common/hexutil"
"github.com/ledgerwatch/erigon/common/u256"
"github.com/ledgerwatch/erigon/consensus"
)
// Draws an validator nonce modulo number of validators.
func GetFromValidatorSet(set ValidatorSet, parent common.Hash, nonce uint) (common.Address, error) {
d, err := set.defaultCaller(parent)
if err != nil {
return common.Address{}, err
}
return set.getWithCaller(parent, nonce, d)
func GetFromValidatorSet(set ValidatorSet, parent common.Hash, nonce uint, call consensus.Call) (common.Address, error) {
//d, err := set.defaultCaller(parent)
//if err != nil {
// return common.Address{}, err
//}
return set.getWithCaller(parent, nonce, call)
}
// Different ways of specifying validators.
@ -52,7 +53,7 @@ func newValidatorSetFromJson(j *ValidatorSetJson, posdaoTransition *uint64) Vali
return &SimpleList{validators: j.List}
}
if j.SafeContract != nil {
return &ValidatorSafeContract{contractAddress: *j.SafeContract, posdaoTransition: posdaoTransition}
return NewValidatorSafeContract(*j.SafeContract, posdaoTransition, nil)
}
if j.Contract != nil {
return &ValidatorContract{

View File

@ -0,0 +1,72 @@
package aura
import (
"testing"
"github.com/ledgerwatch/erigon/common"
"github.com/stretchr/testify/assert"
)
func TestRollingFinality(t *testing.T) {
t.Run("RejectsUnknownSigners", func(t *testing.T) {
f := NewRollingFinality([]common.Address{{1}, {2}, {3}})
_, err := f.push(common.Hash{}, 0, []common.Address{{0}, {4}})
assert.Error(t, err)
_, err = f.push(common.Hash{}, 0, []common.Address{{0}, {1}, {4}})
assert.Error(t, err)
})
t.Run("FinalizeMultiple", func(t *testing.T) {
signers := []common.Address{{0}, {1}, {2}, {3}, {4}, {5}}
f := NewRollingFinality(signers)
// 3 / 6 signers is < 51% so no finality.
for i := 0; i < 6; i++ {
l, err := f.push(common.Hash{byte(i)}, uint64(i%3), []common.Address{signers[i%3]})
assert.NoError(t, err)
assert.Equal(t, 0, len(l))
}
// after pushing a block signed by a fourth validator, the first four
// blocks of the unverified chain become verified.
l, err := f.push(common.Hash{byte(6)}, 6, []common.Address{signers[4]})
assert.NoError(t, err)
for i := uint64(0); i < 4; i++ {
assert.Equal(t, common.Hash{byte(i)}, l[i].hash)
}
assert.Equal(t, 4, len(l))
})
t.Run("FromAncestry", func(t *testing.T) {
signers := []common.Address{{0}, {1}, {2}, {3}, {4}, {5}}
f := NewRollingFinality(signers)
i := 12
get := func(hash common.Hash) ([]common.Address, common.Hash, common.Hash, uint64, bool) {
i--
if i == -1 {
return nil, common.Hash{}, common.Hash{}, 0, false
}
return []common.Address{signers[i%6]}, common.Hash{byte(i)}, common.Hash{byte(i - 1)}, uint64(i), true
}
err := f.buildAncestrySubChain(get, common.Hash{11}, common.Hash{99})
assert.NoError(t, err)
assert.Equal(t, 3, f.headers.l.Len())
assert.Equal(t, common.Hash{11}, *f.lastPushed)
})
t.Run("FromAncestryMultipleSigners", func(t *testing.T) {
signers := []common.Address{{0}, {1}, {2}, {3}, {4}, {5}}
f := NewRollingFinality(signers)
i := 12
get := func(hash common.Hash) ([]common.Address, common.Hash, common.Hash, uint64, bool) {
i--
if i == -1 {
return nil, common.Hash{}, common.Hash{}, 0, false
}
return []common.Address{signers[i%6], signers[(i+1)%6], signers[(i+2)%6]}, common.Hash{byte(i)}, common.Hash{byte(i - 1)}, uint64(i), true
}
err := f.buildAncestrySubChain(get, common.Hash{11}, common.Hash{99})
assert.NoError(t, err)
// only the last hash has < 51% of authorities' signatures
assert.Equal(t, 1, f.headers.l.Len())
assert.Equal(t, common.Hash{11}, f.headers.Front().hash)
assert.Equal(t, common.Hash{11}, *f.lastPushed)
})
}

File diff suppressed because one or more lines are too long

View File

@ -363,19 +363,23 @@ func (c *Clique) Prepare(chain consensus.ChainHeaderReader, header *types.Header
return nil
}
func (c *Clique) Initialize(_ *params.ChainConfig, e consensus.EpochReader, header *types.Header, txs []types.Transaction, uncles []*types.Header, syscall consensus.SystemCall) {
func (c *Clique) Initialize(_ *params.ChainConfig, chain consensus.ChainHeaderReader, e consensus.EpochReader, header *types.Header, txs []types.Transaction, uncles []*types.Header,
syscall consensus.SystemCall, call consensus.Call) {
}
// Finalize implements consensus.Engine, ensuring no uncles are set, nor block
// rewards given.
func (c *Clique) Finalize(_ *params.ChainConfig, header *types.Header, state *state.IntraBlockState, txs []types.Transaction, uncles []*types.Header, r types.Receipts, e consensus.EpochReader, syscall consensus.SystemCall) {
func (c *Clique) Finalize(_ *params.ChainConfig, header *types.Header, state *state.IntraBlockState, txs []types.Transaction, uncles []*types.Header, r types.Receipts,
e consensus.EpochReader, chain consensus.ChainHeaderReader, syscall consensus.SystemCall, call consensus.Call) error {
// No block rewards in PoA, so the state remains as is and uncles are dropped
header.UncleHash = types.CalcUncleHash(nil)
return nil
}
// FinalizeAndAssemble implements consensus.Engine, ensuring no uncles are set,
// nor block rewards given, and returns the final block.
func (c *Clique) FinalizeAndAssemble(chainConfig *params.ChainConfig, header *types.Header, state *state.IntraBlockState, txs []types.Transaction, uncles []*types.Header, receipts types.Receipts, e consensus.EpochReader, syscall consensus.SystemCall) (*types.Block, error) {
func (c *Clique) FinalizeAndAssemble(chainConfig *params.ChainConfig, header *types.Header, state *state.IntraBlockState, txs []types.Transaction, uncles []*types.Header, receipts types.Receipts,
e consensus.EpochReader, chain consensus.ChainHeaderReader, syscall consensus.SystemCall, call consensus.Call) (*types.Block, error) {
// No block rewards in PoA, so the state remains as is and uncles are dropped
header.UncleHash = types.CalcUncleHash(nil)
@ -467,7 +471,7 @@ func (c *Clique) Seal(chain consensus.ChainHeaderReader, block *types.Block, res
return nil
}
func (c *Clique) GenerateSeal(chain consensus.ChainHeaderReader, currnt, parent *types.Header) []rlp.RawValue {
func (c *Clique) GenerateSeal(chain consensus.ChainHeaderReader, currnt, parent *types.Header, call consensus.Call) []rlp.RawValue {
return nil
}

View File

@ -62,6 +62,9 @@ type ChainReader interface {
type EpochReader interface {
GetEpoch(blockHash common.Hash, blockN uint64) (transitionProof []byte, err error)
PutEpoch(blockHash common.Hash, blockN uint64, transitionProof []byte) (err error)
GetPendingEpoch(blockHash common.Hash, blockN uint64) (transitionProof []byte, err error)
PutPendingEpoch(blockHash common.Hash, blockN uint64, transitionProof []byte) (err error)
FindBeforeOrEqualNumber(number uint64) (blockNum uint64, blockHash common.Hash, transitionProof []byte, err error)
}
type SystemCall func(contract common.Address, data []byte) ([]byte, error)
@ -94,14 +97,14 @@ type Engine interface {
Prepare(chain ChainHeaderReader, header *types.Header) error
// Initialize runs any pre-transaction state modifications (e.g. epoch start)
Initialize(config *params.ChainConfig, e EpochReader, header *types.Header, txs []types.Transaction, uncles []*types.Header, syscall SystemCall)
Initialize(config *params.ChainConfig, chain ChainHeaderReader, e EpochReader, header *types.Header, txs []types.Transaction, uncles []*types.Header, syscall SystemCall, call Call)
// Finalize runs any post-transaction state modifications (e.g. block rewards)
// but does not assemble the block.
//
// Note: The block header and state database might be updated to reflect any
// consensus rules that happen at finalization (e.g. block rewards).
Finalize(config *params.ChainConfig, header *types.Header, state *state.IntraBlockState, txs []types.Transaction, uncles []*types.Header, r types.Receipts, e EpochReader, syscall SystemCall)
Finalize(config *params.ChainConfig, header *types.Header, state *state.IntraBlockState, txs []types.Transaction, uncles []*types.Header, r types.Receipts, e EpochReader, chain ChainHeaderReader, syscall SystemCall, call Call) error
// FinalizeAndAssemble runs any post-transaction state modifications (e.g. block
// rewards) and assembles the final block.
@ -109,7 +112,7 @@ type Engine interface {
// Note: The block header and state database might be updated to reflect any
// consensus rules that happen at finalization (e.g. block rewards).
FinalizeAndAssemble(config *params.ChainConfig, header *types.Header, state *state.IntraBlockState, txs []types.Transaction,
uncles []*types.Header, receipts types.Receipts, e EpochReader, syscall SystemCall) (*types.Block, error)
uncles []*types.Header, receipts types.Receipts, e EpochReader, chain ChainHeaderReader, syscall SystemCall, call Call) (*types.Block, error)
// Seal generates a new sealing request for the given input block and pushes
// the result into the given channel.
@ -125,7 +128,7 @@ type Engine interface {
// that a new block should have.
CalcDifficulty(chain ChainHeaderReader, time, parentTime uint64, parentDifficulty *big.Int, parentNumber uint64, parentHash, parentUncleHash common.Hash, parentSeal []rlp.RawValue) *big.Int
GenerateSeal(chain ChainHeaderReader, currnt, parent *types.Header) []rlp.RawValue
GenerateSeal(chain ChainHeaderReader, currnt, parent *types.Header, call Call) []rlp.RawValue
// VerifyFamily only used by Aura now - later may be merged into VerifyHeaders
VerifyFamily(chain ChainHeaderReader, header *types.Header) error

View File

@ -328,7 +328,7 @@ func (ethash *Ethash) verifyHeader(chain consensus.ChainHeaderReader, header, pa
return nil
}
func (ethash *Ethash) GenerateSeal(chain consensus.ChainHeaderReader, currnt, parent *types.Header) []rlp.RawValue {
func (ethash *Ethash) GenerateSeal(chain consensus.ChainHeaderReader, currnt, parent *types.Header, call consensus.Call) []rlp.RawValue {
return nil
}
@ -596,22 +596,26 @@ func (ethash *Ethash) Prepare(chain consensus.ChainHeaderReader, header *types.H
return nil
}
func (ethash *Ethash) Initialize(config *params.ChainConfig, e consensus.EpochReader, header *types.Header, txs []types.Transaction, uncles []*types.Header, _ consensus.SystemCall) {
func (ethash *Ethash) Initialize(config *params.ChainConfig, chain consensus.ChainHeaderReader, e consensus.EpochReader, header *types.Header, txs []types.Transaction, uncles []*types.Header,
_ consensus.SystemCall, _ consensus.Call) {
}
// Finalize implements consensus.Engine, accumulating the block and uncle rewards,
// setting the final state on the header
func (ethash *Ethash) Finalize(config *params.ChainConfig, header *types.Header, state *state.IntraBlockState, txs []types.Transaction, uncles []*types.Header, r types.Receipts, e consensus.EpochReader, _ consensus.SystemCall) {
func (ethash *Ethash) Finalize(config *params.ChainConfig, header *types.Header, state *state.IntraBlockState, txs []types.Transaction, uncles []*types.Header, r types.Receipts,
e consensus.EpochReader, chain consensus.ChainHeaderReader, _ consensus.SystemCall, call consensus.Call) error {
// Accumulate any block and uncle rewards and commit the final state root
accumulateRewards(config, state, header, uncles)
return nil
}
// FinalizeAndAssemble implements consensus.Engine, accumulating the block and
// uncle rewards, setting the final state and assembling the block.
func (ethash *Ethash) FinalizeAndAssemble(chainConfig *params.ChainConfig, header *types.Header, state *state.IntraBlockState, txs []types.Transaction, uncles []*types.Header, r types.Receipts, e consensus.EpochReader, syscall consensus.SystemCall) (*types.Block, error) {
func (ethash *Ethash) FinalizeAndAssemble(chainConfig *params.ChainConfig, header *types.Header, state *state.IntraBlockState, txs []types.Transaction, uncles []*types.Header, r types.Receipts,
e consensus.EpochReader, chain consensus.ChainHeaderReader, syscall consensus.SystemCall, call consensus.Call) (*types.Block, error) {
// Finalize block
ethash.Finalize(chainConfig, header, state, txs, uncles, r, e, syscall)
ethash.Finalize(chainConfig, header, state, txs, uncles, r, e, chain, syscall, call)
// Header seems complete, assemble into a block and return
return types.NewBlock(header, txs, uncles, r), nil
}

View File

@ -96,6 +96,7 @@ func ExecuteBlockEphemerally(
stateReader state.StateReader,
stateWriter state.WriterWithChangeSets,
epochReader consensus.EpochReader,
chainReader consensus.ChainHeaderReader,
checkTEVM func(codeHash common.Hash) (bool, error),
) (types.Receipts, error) {
defer blockExecutionTimer.UpdateSince(time.Now())
@ -108,7 +109,7 @@ func ExecuteBlockEphemerally(
gp.AddGas(block.GasLimit())
if !vmConfig.ReadOnly {
if err := InitializeBlockExecution(engine, epochReader, block.Header(), block.Transactions(), block.Uncles(), chainConfig, ibs); err != nil {
if err := InitializeBlockExecution(engine, chainReader, epochReader, block.Header(), block.Transactions(), block.Uncles(), chainConfig, ibs); err != nil {
return nil, err
}
}
@ -167,7 +168,7 @@ func ExecuteBlockEphemerally(
}
}
if !vmConfig.ReadOnly {
if err := FinalizeBlockExecution(engine, block.Header(), block.Transactions(), block.Uncles(), stateWriter, chainConfig, ibs, receipts, epochReader); err != nil {
if err := FinalizeBlockExecution(engine, block.Header(), block.Transactions(), block.Uncles(), stateWriter, chainConfig, ibs, receipts, epochReader, chainReader); err != nil {
return nil, err
}
}
@ -264,14 +265,19 @@ func CallContractTx(contract common.Address, data []byte, ibs *state.IntraBlockS
func FinalizeBlockExecution(engine consensus.Engine, header *types.Header,
txs types.Transactions, uncles []*types.Header, stateWriter state.WriterWithChangeSets, cc *params.ChainConfig,
ibs *state.IntraBlockState, receipts types.Receipts, e consensus.EpochReader,
ibs *state.IntraBlockState, receipts types.Receipts, e consensus.EpochReader, headerReader consensus.ChainHeaderReader,
) error {
//ibs.Print(cc.Rules(header.Number.Uint64()))
//fmt.Printf("====tx processing end====\n")
engine.Finalize(cc, header, ibs, txs, uncles, receipts, e, func(contract common.Address, data []byte) ([]byte, error) {
if err := engine.Finalize(cc, header, ibs, txs, uncles, receipts, e, headerReader, func(contract common.Address, data []byte) ([]byte, error) {
return SysCallContract(contract, data, *cc, ibs, header, engine)
}, func(contract common.Address, data []byte) ([]byte, error) {
return CallContract(contract, data, *cc, ibs, header, engine)
})
}); err != nil {
return err
}
//fmt.Printf("====finalize start====\n")
//ibs.Print(cc.Rules(header.Number.Uint64()))
//fmt.Printf("====finalize end====\n")
@ -293,10 +299,12 @@ func FinalizeBlockExecution(engine consensus.Engine, header *types.Header,
return nil
}
func InitializeBlockExecution(engine consensus.Engine, epochReader consensus.EpochReader, header *types.Header, txs types.Transactions, uncles []*types.Header, cc *params.ChainConfig, ibs *state.IntraBlockState) error {
func InitializeBlockExecution(engine consensus.Engine, chain consensus.ChainHeaderReader, epochReader consensus.EpochReader, header *types.Header, txs types.Transactions, uncles []*types.Header, cc *params.ChainConfig, ibs *state.IntraBlockState) error {
// Finalize the block, applying any consensus engine specific extras (e.g. block rewards)
engine.Initialize(cc, epochReader, header, txs, uncles, func(contract common.Address, data []byte) ([]byte, error) {
engine.Initialize(cc, chain, epochReader, header, txs, uncles, func(contract common.Address, data []byte) ([]byte, error) {
return SysCallContract(contract, data, *cc, ibs, header, engine)
}, func(contract common.Address, data []byte) ([]byte, error) {
return CallContract(contract, data, *cc, ibs, header, engine)
})
//fmt.Printf("====InitializeBlockExecution start %d====\n", header.Number.Uint64())
//ibs.Print(cc.Rules(header.Number.Uint64()))

View File

@ -276,7 +276,7 @@ func GenerateChain(config *params.ChainConfig, parent *types.Block, engine conse
}
if b.engine != nil {
// Finalize and seal the block
if _, err := b.engine.FinalizeAndAssemble(config, b.header, ibs, b.txs, b.uncles, b.receipts, nil, nil); err != nil {
if _, err := b.engine.FinalizeAndAssemble(config, b.header, ibs, b.txs, b.uncles, b.receipts, nil, nil, nil, nil); err != nil {
return nil, nil, fmt.Errorf("call to FinaliseAndAssemble: %w", err)
}
// Write state changes to db
@ -408,7 +408,7 @@ func makeHeader(chain consensus.ChainReader, parent *types.Block, state *state.I
Number: new(big.Int).Add(parent.Number(), common.Big1),
Time: time,
}
header.Seal = engine.GenerateSeal(chain, header, parent.Header())
header.Seal = engine.GenerateSeal(chain, header, parent.Header(), nil)
if chain.Config().IsLondon(header.Number.Uint64()) {
header.BaseFee = misc.CalcBaseFee(chain.Config(), parent.Header())

View File

@ -877,15 +877,56 @@ func ReadAncestor(db ethdb.KVGetter, hash common.Hash, number, ancestor uint64,
}
func ReadEpoch(tx ethdb.Tx, blockNum uint64, blockHash common.Hash) (transitionProof []byte, err error) {
k := make([]byte, 8+32)
k := make([]byte, dbutils.NumberLength+common.HashLength)
binary.BigEndian.PutUint64(k, blockNum)
copy(k[8:], blockHash[:])
copy(k[dbutils.NumberLength:], blockHash[:])
return tx.GetOne(dbutils.Epoch, k)
}
func FindEpochBeforeOrEqualNumber(tx ethdb.Tx, n uint64) (blockNum uint64, blockHash common.Hash, transitionProof []byte, err error) {
c, err := tx.Cursor(dbutils.Epoch)
if err != nil {
return 0, common.Hash{}, nil, err
}
defer c.Close()
k := make([]byte, dbutils.NumberLength)
binary.BigEndian.PutUint64(k, n)
k, v, err := c.Seek(k)
if err != nil {
return 0, common.Hash{}, nil, err
}
if k != nil {
num := binary.BigEndian.Uint64(k)
if num == n {
return n, common.BytesToHash(k[dbutils.NumberLength:]), v, nil
}
}
k, v, err = c.Prev()
if err != nil {
return 0, common.Hash{}, nil, err
}
if k == nil {
return 0, common.Hash{}, nil, nil
}
return binary.BigEndian.Uint64(k), common.BytesToHash(k[dbutils.NumberLength:]), v, nil
}
func WriteEpoch(tx ethdb.RwTx, blockNum uint64, blockHash common.Hash, transitionProof []byte) (err error) {
k := make([]byte, dbutils.NumberLength+common.HashLength)
binary.BigEndian.PutUint64(k, blockNum)
copy(k[dbutils.NumberLength:], blockHash[:])
return tx.Put(dbutils.Epoch, k, transitionProof)
}
func ReadPendingEpoch(tx ethdb.Tx, blockNum uint64, blockHash common.Hash) (transitionProof []byte, err error) {
k := make([]byte, 8+32)
binary.BigEndian.PutUint64(k, blockNum)
copy(k[8:], blockHash[:])
return tx.Put(dbutils.Epoch, k, transitionProof)
return tx.GetOne(dbutils.PendingEpoch, k)
}
func WritePendingEpoch(tx ethdb.RwTx, blockNum uint64, blockHash common.Hash, transitionProof []byte) (err error) {
k := make([]byte, 8+32)
binary.BigEndian.PutUint64(k, blockNum)
copy(k[8:], blockHash[:])
return tx.Put(dbutils.PendingEpoch, k, transitionProof)
}

View File

@ -172,6 +172,7 @@ func promoteCallTraces(logPrefix string, tx ethdb.RwTx, startBlock, endBlock uin
if err = flushBitmaps64(collectorTo, tos); err != nil {
return err
}
// Clean up before loading call traces to reclaim space
var prunedMin uint64 = math.MaxUint64
var prunedMax uint64 = 0

View File

@ -112,7 +112,7 @@ func executeBlock(
callTracer := NewCallTracer(checkTEVM)
vmConfig.Debug = true
vmConfig.Tracer = callTracer
receipts, err := core.ExecuteBlockEphemerally(cfg.chainConfig, &vmConfig, getHeader, cfg.engine, block, stateReader, stateWriter, epochReader{tx: tx}, checkTEVM)
receipts, err := core.ExecuteBlockEphemerally(cfg.chainConfig, &vmConfig, getHeader, cfg.engine, block, stateReader, stateWriter, epochReader{tx: tx}, chainReader{config: cfg.chainConfig, tx: tx}, checkTEVM)
if err != nil {
return err
}

View File

@ -364,6 +364,15 @@ func (cr epochReader) GetEpoch(hash common.Hash, number uint64) ([]byte, error)
func (cr epochReader) PutEpoch(hash common.Hash, number uint64, proof []byte) error {
return rawdb.WriteEpoch(cr.tx, number, hash, proof)
}
func (cr epochReader) GetPendingEpoch(hash common.Hash, number uint64) ([]byte, error) {
return rawdb.ReadPendingEpoch(cr.tx, number, hash)
}
func (cr epochReader) PutPendingEpoch(hash common.Hash, number uint64, proof []byte) error {
return rawdb.WritePendingEpoch(cr.tx, number, hash, proof)
}
func (cr epochReader) FindBeforeOrEqualNumber(number uint64) (blockNum uint64, blockHash common.Hash, transitionProof []byte, err error) {
return rawdb.FindEpochBeforeOrEqualNumber(cr.tx, number)
}
func HeadersPrune(p *PruneState, tx ethdb.RwTx, cfg HeadersCfg, ctx context.Context) (err error) {
useExternalTx := tx != nil

View File

@ -104,7 +104,7 @@ func SpawnMiningExecStage(s *StageState, tx ethdb.RwTx, cfg MiningExecCfg, quit
}
}
if err := core.FinalizeBlockExecution(cfg.engine, current.Header, current.Txs, current.Uncles, stateWriter, &cfg.chainConfig, ibs, nil, nil); err != nil {
if err := core.FinalizeBlockExecution(cfg.engine, current.Header, current.Txs, current.Uncles, stateWriter, &cfg.chainConfig, ibs, nil, nil, nil); err != nil {
return err
}

View File

@ -85,8 +85,8 @@ func TxLookupTransform(logPrefix string, tx ethdb.RwTx, startKey, endKey []byte,
return fmt.Errorf("%s: tx lookup generation, empty block body %d, hash %x", logPrefix, blocknum, v)
}
for _, tx := range body.Transactions {
if err := next(k, tx.Hash().Bytes(), bigNum.SetUint64(blocknum).Bytes()); err != nil {
for _, txn := range body.Transactions {
if err := next(k, txn.Hash().Bytes(), bigNum.SetUint64(blocknum).Bytes()); err != nil {
return err
}
}

View File

@ -167,7 +167,7 @@ func runBlock(ibs *state.IntraBlockState, txnWriter state.StateWriter, blockWrit
if !vmConfig.ReadOnly {
// Finalize the block, applying any consensus engine specific extras (e.g. block rewards)
if _, err := engine.FinalizeAndAssemble(chainConfig, header, ibs, block.Transactions(), block.Uncles(), receipts, nil, nil); err != nil {
if _, err := engine.FinalizeAndAssemble(chainConfig, header, ibs, block.Transactions(), block.Uncles(), receipts, nil, nil, nil, nil); err != nil {
return nil, fmt.Errorf("finalize of block %d failed: %v", block.NumberU64(), err)
}

View File

@ -46,14 +46,18 @@ func (c *powEngine) VerifySeal(chain consensus.ChainHeaderReader, header *types.
func (c *powEngine) Prepare(chain consensus.ChainHeaderReader, header *types.Header) error {
panic("must not be called")
}
func (c *powEngine) Initialize(chainConfig *params.ChainConfig, e consensus.EpochReader, header *types.Header, txs []types.Transaction, uncles []*types.Header, syscall consensus.SystemCall) {
func (c *powEngine) Initialize(chainConfig *params.ChainConfig, chain consensus.ChainHeaderReader, e consensus.EpochReader, header *types.Header, txs []types.Transaction, uncles []*types.Header,
syscall consensus.SystemCall, call consensus.Call) {
panic("must not be called")
}
func (c *powEngine) Finalize(chainConfig *params.ChainConfig, header *types.Header, state *state.IntraBlockState, txs []types.Transaction, uncles []*types.Header, r types.Receipts, e consensus.EpochReader, syscall consensus.SystemCall) {
func (c *powEngine) Finalize(chainConfig *params.ChainConfig, header *types.Header, state *state.IntraBlockState,
txs []types.Transaction, uncles []*types.Header, r types.Receipts,
e consensus.EpochReader, h consensus.ChainHeaderReader, syscall consensus.SystemCall, call consensus.Call) error {
panic("must not be called")
}
func (c *powEngine) FinalizeAndAssemble(chainConfig *params.ChainConfig, header *types.Header, state *state.IntraBlockState, txs []types.Transaction,
uncles []*types.Header, receipts types.Receipts, e consensus.EpochReader, syscall consensus.SystemCall) (*types.Block, error) {
func (c *powEngine) FinalizeAndAssemble(chainConfig *params.ChainConfig, header *types.Header, state *state.IntraBlockState,
txs []types.Transaction, uncles []*types.Header, receipts types.Receipts,
e consensus.EpochReader, h consensus.ChainHeaderReader, syscall consensus.SystemCall, call consensus.Call) (*types.Block, error) {
panic("must not be called")
}
@ -64,7 +68,7 @@ func (c *powEngine) SealHash(header *types.Header) common.Hash {
panic("must not be called")
}
func (c *powEngine) GenerateSeal(chain consensus.ChainHeaderReader, currnt, parent *types.Header) []rlp.RawValue {
func (c *powEngine) GenerateSeal(chain consensus.ChainHeaderReader, currnt, parent *types.Header, call consensus.Call) []rlp.RawValue {
return nil
}