Skip to content
This repository has been archived by the owner on Apr 10, 2024. It is now read-only.

Commit

Permalink
Revert "Add Parlia consensus engine for Binance Smart Chain support (e…
Browse files Browse the repository at this point in the history
…rigontech#3086)"

This reverts commit ee99f17.
  • Loading branch information
dmitry123 committed Dec 17, 2021
1 parent c897053 commit 8d22c97
Show file tree
Hide file tree
Showing 29 changed files with 224 additions and 1,483 deletions.
2 changes: 1 addition & 1 deletion cmd/hack/hack.go
Original file line number Diff line number Diff line change
Expand Up @@ -3635,7 +3635,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, 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: %w", block.NumberU64(), err)
}

Expand Down
8 changes: 2 additions & 6 deletions cmd/integration/commands/stages.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"github.com/ledgerwatch/erigon/cmd/rpcdaemon/interfaces"
"github.com/ledgerwatch/erigon/cmd/sentry/sentry"
"github.com/ledgerwatch/erigon/cmd/utils"
"github.com/ledgerwatch/erigon/common"
"github.com/ledgerwatch/erigon/common/dbutils"
"github.com/ledgerwatch/erigon/consensus"
"github.com/ledgerwatch/erigon/consensus/ethash"
Expand Down Expand Up @@ -1075,15 +1074,12 @@ func newSync(ctx context.Context, db kv.RwDB, miningConfig *params.MiningConfig)

genesis, chainConfig := byChain()
var engine consensus.Engine
config := &ethconfig.Defaults
var consensusConfig interface{}
if chainConfig.Clique != nil {
c := params.CliqueSnapshot
c.DBPath = path.Join(datadir, "clique/db")
engine = ethconfig.CreateConsensusEngine(chainConfig, logger, c, config.Miner.Notify, config.Miner.Noverify, common.Hash{})
engine = ethconfig.CreateConsensusEngine(chainConfig, logger, c, nil, false)
} else if chainConfig.Aura != nil {
consensusConfig = &params.AuRaConfig{DBPath: path.Join(datadir, "aura")}
engine = ethconfig.CreateConsensusEngine(chainConfig, logger, consensusConfig, config.Miner.Notify, config.Miner.Noverify, common.Hash{})
engine = ethconfig.CreateConsensusEngine(chainConfig, logger, &params.AuRaConfig{DBPath: path.Join(datadir, "aura")}, nil, false)
} else { //ethash
engine = ethash.NewFaker()
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/state/commands/opcode_tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,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, 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: %w", block.NumberU64(), err)
}

Expand Down
17 changes: 8 additions & 9 deletions common/u256/big.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,12 @@ import (

// Common big integers often used
var (
Num0 = uint256.NewInt(0)
Num1 = uint256.NewInt(1)
Num2 = uint256.NewInt(2)
Num4 = uint256.NewInt(4)
Num8 = uint256.NewInt(8)
Num27 = uint256.NewInt(27)
Num32 = uint256.NewInt(32)
Num35 = uint256.NewInt(35)
Num148 = uint256.NewInt(148)
Num0 = uint256.NewInt(0)
Num1 = uint256.NewInt(1)
Num2 = uint256.NewInt(2)
Num4 = uint256.NewInt(4)
Num8 = uint256.NewInt(8)
Num27 = uint256.NewInt(27)
Num32 = uint256.NewInt(32)
Num35 = uint256.NewInt(35)
)
18 changes: 9 additions & 9 deletions consensus/aura/aura.go
Original file line number Diff line number Diff line change
Expand Up @@ -826,11 +826,11 @@ func (c *AuRa) Initialize(config *params.ChainConfig, chain consensus.ChainHeade
}

//word `signal epoch` == word `pending epoch`
func (c *AuRa) 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, syscall consensus.SystemCall) (systemTxs []types.Transaction, usedGas uint64, err error) {
func (c *AuRa) 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, syscall consensus.SystemCall) error {
// accumulateRewards retrieves rewards for a block and applies them to the coinbase accounts for miner and uncle miners
beneficiaries, _, rewards, err := AccumulateRewards(config, c, header, uncles, syscall)
if err != nil {
return systemTxs, usedGas, fmt.Errorf("buildAncestrySubChain: %w", err)
return fmt.Errorf("buildAncestrySubChain: %w", err)
}
for i := range beneficiaries {
//fmt.Printf("beneficiary: n=%d, %x,%d\n", header.Number.Uint64(), beneficiaries[i], rewards[i])
Expand All @@ -843,14 +843,14 @@ func (c *AuRa) Finalize(config *params.ChainConfig, header *types.Header, state
}
pendingTransitionProof, err := c.cfg.Validators.signalEpochEnd(header.Number.Uint64() == 0, header, r)
if err != nil {
return systemTxs, usedGas, err
return err
}
if pendingTransitionProof != nil {
if header.Number.Uint64() >= DEBUG_LOG_FROM {
fmt.Printf("insert_pending_trancition: %d,receipts=%d, lenProof=%d\n", header.Number.Uint64(), len(r), len(pendingTransitionProof))
}
if err = e.PutPendingEpoch(header.Hash(), header.Number.Uint64(), pendingTransitionProof); err != nil {
return systemTxs, usedGas, err
return err
}
}
// check_and_lock_block -> check_epoch_end_signal END
Expand All @@ -859,17 +859,17 @@ func (c *AuRa) Finalize(config *params.ChainConfig, header *types.Header, state
c.EpochManager.finalityChecker.print(header.Number.Uint64())
epochEndProof, err := isEpochEnd(chain, e, finalized, header)
if err != nil {
return systemTxs, usedGas, err
return err
}
if epochEndProof != nil {
c.EpochManager.noteNewEpoch()
log.Info("[aura] epoch transition", "block_num", header.Number.Uint64())
if err := e.PutEpoch(header.Hash(), header.Number.Uint64(), epochEndProof); err != nil {
return systemTxs, usedGas, err
return err
}
}

return systemTxs, usedGas, nil
return nil
}

func buildFinality(e *EpochManager, chain consensus.ChainHeaderReader, er consensus.EpochReader, validators ValidatorSet, header *types.Header, syscall consensus.SystemCall) []unAssembledHeader {
Expand Down Expand Up @@ -970,11 +970,11 @@ func allHeadersUntil(chain consensus.ChainHeaderReader, from *types.Header, to c

// FinalizeAndAssemble implements consensus.Engine
func (c *AuRa) 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, []*types.Receipt, error) {
e consensus.EpochReader, chain consensus.ChainHeaderReader, syscall consensus.SystemCall, call consensus.Call) (*types.Block, error) {
c.Finalize(chainConfig, header, state, txs, uncles, r, e, chain, syscall)

// Assemble and return the final block for sealing
return types.NewBlock(header, txs, uncles, r), r, nil
return types.NewBlock(header, txs, uncles, r), nil
}

// Authorize injects a private key into the consensus engine to mint new blocks
Expand Down
9 changes: 4 additions & 5 deletions consensus/clique/clique.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,22 +354,21 @@ func (c *Clique) Initialize(config *params.ChainConfig, chain consensus.ChainHea

// Finalize implements consensus.Engine, ensuring no uncles are set, nor block
// rewards given.
func (c *Clique) Finalize(config *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) (systemTxs []types.Transaction, usedGas uint64, err error) {
func (c *Clique) 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, syscall consensus.SystemCall) error {
// No block rewards in PoA, so the state remains as is and uncles are dropped
header.UncleHash = types.CalcUncleHash(nil)
return systemTxs, usedGas, 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, chain consensus.ChainHeaderReader, syscall consensus.SystemCall, call consensus.Call) (*types.Block, []*types.Receipt, error) {
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.Root = state.IntermediateRoot(chain.Config().IsEIP158(header.Number)) // Covalent todo: Is this needed? We will have to resolve it
header.UncleHash = types.CalcUncleHash(nil)

// Assemble and return the final block for sealing
return types.NewBlock(header, txs, nil, receipts), receipts, nil
return types.NewBlock(header, txs, nil, receipts), nil
}

// Authorize injects a private key into the consensus engine to mint new blocks
Expand Down
18 changes: 2 additions & 16 deletions consensus/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ import (
"github.com/ledgerwatch/erigon/rpc"
)

var (
SystemAddress = common.HexToAddress("0xffffFFFfFFffffffffffffffFfFFFfffFFFfFFfE")
)

// ChainHeaderReader defines a small collection of methods needed to access the local
// blockchain during header verification.
type ChainHeaderReader interface {
Expand Down Expand Up @@ -105,15 +101,15 @@ 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).
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) (systemTxs []types.Transaction, usedGas uint64, err error)
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) error

// FinalizeAndAssemble runs any post-transaction state modifications (e.g. block
// rewards) and assembles the final block.
//
// 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, chain ChainHeaderReader, syscall SystemCall, call Call) (*types.Block, []*types.Receipt, 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.
Expand Down Expand Up @@ -145,13 +141,3 @@ type PoW interface {
// Hashrate returns the current mining hashrate of a PoW consensus engine.
Hashrate() float64
}

// PoSA is a consensus engine based on proof-of-stake-authority used by Binance Smart Chain.
type PoSA interface {
Engine

IsSystemTransaction(tx *types.Transaction, header *types.Header) (bool, error)
IsSystemContract(to *common.Address) bool
EnoughDistance(chain ChainReader, header *types.Header) bool
IsLocalBlock(header *types.Header) bool
}
8 changes: 4 additions & 4 deletions consensus/ethash/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -530,21 +530,21 @@ func (ethash *Ethash) Initialize(config *params.ChainConfig, chain consensus.Cha

// 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, receipts types.Receipts, e consensus.EpochReader, chain consensus.ChainHeaderReader, syscall consensus.SystemCall) (systemTxs []types.Transaction, usedGas uint64, err error) {
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, syscall consensus.SystemCall) error {
// Accumulate any block and uncle rewards and commit the final state root
accumulateRewards(config, state, header, uncles)
return nil, usedGas, nil
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, chain consensus.ChainHeaderReader, syscall consensus.SystemCall, call consensus.Call) (*types.Block, []*types.Receipt, error) {
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, chain, syscall)
// Header seems complete, assemble into a block and return
return types.NewBlock(header, txs, uncles, r), r, nil
return types.NewBlock(header, txs, uncles, r), nil
}

// SealHash returns the hash of a block prior to it being sealed.
Expand Down
Loading

0 comments on commit 8d22c97

Please sign in to comment.