mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2025-01-20 09:21:11 +00:00
Refactor and simplify PulseChain integration
This commit is contained in:
parent
293afaa131
commit
5df5fd995b
@ -371,7 +371,6 @@ func (c *Clique) Finalize(config *chain.Config, header *types.Header, state *sta
|
|||||||
txs types.Transactions, uncles []*types.Header, r types.Receipts, withdrawals []*types.Withdrawal,
|
txs types.Transactions, uncles []*types.Header, r types.Receipts, withdrawals []*types.Withdrawal,
|
||||||
e consensus.EpochReader, chain consensus.ChainHeaderReader, syscall consensus.SystemCall,
|
e consensus.EpochReader, chain consensus.ChainHeaderReader, syscall consensus.SystemCall,
|
||||||
) (types.Transactions, types.Receipts, error) {
|
) (types.Transactions, types.Receipts, error) {
|
||||||
|
|
||||||
// No block rewards in PoA, so the state remains as is and uncles are dropped
|
// No block rewards in PoA, so the state remains as is and uncles are dropped
|
||||||
header.UncleHash = types.CalcUncleHash(nil)
|
header.UncleHash = types.CalcUncleHash(nil)
|
||||||
return txs, r, nil
|
return txs, r, nil
|
||||||
|
@ -565,7 +565,7 @@ func (ethash *Ethash) Finalize(config *chain.Config, header *types.Header, state
|
|||||||
e consensus.EpochReader, chain consensus.ChainHeaderReader, syscall consensus.SystemCall,
|
e consensus.EpochReader, chain consensus.ChainHeaderReader, syscall consensus.SystemCall,
|
||||||
) (types.Transactions, types.Receipts, error) {
|
) (types.Transactions, types.Receipts, error) {
|
||||||
// Apply fork changes on PrimordialPulse block
|
// Apply fork changes on PrimordialPulse block
|
||||||
if cfg := chain.Config(); cfg.PulseChain != nil && cfg.PrimordialPulseBlock.Uint64() == header.Number.Uint64() {
|
if cfg := chain.Config(); cfg.IsPrimordialPulseBlock(header.Number.Uint64()) {
|
||||||
pulse.PrimordialPulseFork(state, cfg.PulseChain)
|
pulse.PrimordialPulseFork(state, cfg.PulseChain)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,7 +16,6 @@ import (
|
|||||||
"github.com/ledgerwatch/erigon/core/state"
|
"github.com/ledgerwatch/erigon/core/state"
|
||||||
"github.com/ledgerwatch/erigon/core/types"
|
"github.com/ledgerwatch/erigon/core/types"
|
||||||
"github.com/ledgerwatch/erigon/params"
|
"github.com/ledgerwatch/erigon/params"
|
||||||
"github.com/ledgerwatch/erigon/pulse"
|
|
||||||
"github.com/ledgerwatch/erigon/rpc"
|
"github.com/ledgerwatch/erigon/rpc"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -85,17 +84,9 @@ func (s *Serenity) VerifyHeader(chain consensus.ChainHeaderReader, header *types
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if !reached {
|
if !reached && (chain.Config().PulseChain == nil || !IsPoSHeader(header)) {
|
||||||
if chain.Config().PulseChain == nil {
|
// Delegate non-PoS block to eth1 verification
|
||||||
// Not verifying seals if the TTD is passed
|
return s.eth1Engine.VerifyHeader(chain, header, !chain.Config().TerminalTotalDifficultyPassed)
|
||||||
return s.eth1Engine.VerifyHeader(chain, header, !chain.Config().TerminalTotalDifficultyPassed)
|
|
||||||
} else if !pulse.IsBeaconBlock(header.Number.Uint64()) {
|
|
||||||
// If this is not a PoS block then verify as PoW block
|
|
||||||
return s.eth1Engine.VerifyHeader(chain, header, !chain.Config().TerminalTotalDifficultyPassed)
|
|
||||||
} else if chain.Config().PrimordialPulseBlock.Cmp(header.Number) == 0 {
|
|
||||||
// If this is the PulseChain fork block then verify as PoW block
|
|
||||||
return s.eth1Engine.VerifyHeader(chain, header, !chain.Config().TerminalTotalDifficultyPassed)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// Short circuit if the parent is not known
|
// Short circuit if the parent is not known
|
||||||
parent := chain.GetHeader(header.ParentHash, header.Number.Uint64()-1)
|
parent := chain.GetHeader(header.ParentHash, header.Number.Uint64()-1)
|
||||||
@ -125,15 +116,7 @@ func (s *Serenity) Prepare(chain consensus.ChainHeaderReader, header *types.Head
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if !reached {
|
if !reached {
|
||||||
if chain.Config().PulseChain == nil {
|
return s.eth1Engine.Prepare(chain, header, state)
|
||||||
return s.eth1Engine.Prepare(chain, header, state)
|
|
||||||
} else if !pulse.IsBeaconBlock(header.Number.Uint64()) {
|
|
||||||
// If this is not a PoS block then verify as PoW block
|
|
||||||
return s.eth1Engine.Prepare(chain, header, state)
|
|
||||||
} else if chain.Config().PrimordialPulseBlock.Cmp(header.Number) == 0 {
|
|
||||||
// If this is the PulseChain fork block then verify as PoW block
|
|
||||||
return s.eth1Engine.Prepare(chain, header, state)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
header.Difficulty = SerenityDifficulty
|
header.Difficulty = SerenityDifficulty
|
||||||
header.Nonce = SerenityNonce
|
header.Nonce = SerenityNonce
|
||||||
@ -187,15 +170,7 @@ func (s *Serenity) CalcDifficulty(chain consensus.ChainHeaderReader, time, paren
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if !reached {
|
if !reached {
|
||||||
if chain.Config().PulseChain == nil {
|
return s.eth1Engine.CalcDifficulty(chain, time, parentTime, parentDifficulty, parentNumber, parentHash, parentUncleHash, parentAuRaStep)
|
||||||
return s.eth1Engine.CalcDifficulty(chain, time, parentTime, parentDifficulty, parentNumber, parentHash, parentUncleHash, parentAuRaStep)
|
|
||||||
} else if !pulse.IsBeaconBlock(parentNumber) {
|
|
||||||
// If this is not a PoS block then verify as PoW block
|
|
||||||
return s.eth1Engine.CalcDifficulty(chain, time, parentTime, parentDifficulty, parentNumber, parentHash, parentUncleHash, parentAuRaStep)
|
|
||||||
} else if chain.Config().PrimordialPulseBlock.Uint64() == parentNumber {
|
|
||||||
// If this is the PulseChain fork block then verify as PoW block
|
|
||||||
return s.eth1Engine.CalcDifficulty(chain, time, parentTime, parentDifficulty, parentNumber, parentHash, parentUncleHash, parentAuRaStep)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return SerenityDifficulty
|
return SerenityDifficulty
|
||||||
}
|
}
|
||||||
@ -294,14 +269,6 @@ func IsPoSHeader(header *types.Header) bool {
|
|||||||
// It depends on the parentHash already being stored in the database.
|
// It depends on the parentHash already being stored in the database.
|
||||||
// If the total difficulty is not stored in the database a ErrUnknownAncestorTD error is returned.
|
// If the total difficulty is not stored in the database a ErrUnknownAncestorTD error is returned.
|
||||||
func IsTTDReached(chain consensus.ChainHeaderReader, parentHash libcommon.Hash, number uint64) (bool, error) {
|
func IsTTDReached(chain consensus.ChainHeaderReader, parentHash libcommon.Hash, number uint64) (bool, error) {
|
||||||
if chain.Config().PulseChain != nil {
|
|
||||||
// Any parent before PulseChain should return false
|
|
||||||
if number < chain.Config().PrimordialPulseBlock.Uint64() {
|
|
||||||
return false, nil
|
|
||||||
}
|
|
||||||
// If the parent is the PulseChain fork block or after return TTDReached
|
|
||||||
return true, nil
|
|
||||||
}
|
|
||||||
if chain.Config().TerminalTotalDifficulty == nil {
|
if chain.Config().TerminalTotalDifficulty == nil {
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,6 @@ import (
|
|||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/ledgerwatch/erigon-lib/chain"
|
|
||||||
"math"
|
"math"
|
||||||
"math/big"
|
"math/big"
|
||||||
"time"
|
"time"
|
||||||
@ -1625,17 +1624,7 @@ func WritePendingEpoch(tx kv.RwTx, blockNum uint64, blockHash libcommon.Hash, tr
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Transitioned returns true if the block number comes after POS transition or is the last POW block
|
// Transitioned returns true if the block number comes after POS transition or is the last POW block
|
||||||
func Transitioned(db kv.Getter, blockNum uint64, chain chain.Config) (trans bool, err error) {
|
func Transitioned(db kv.Getter, blockNum uint64, terminalTotalDifficulty *big.Int) (trans bool, err error) {
|
||||||
terminalTotalDifficulty := chain.TerminalTotalDifficulty
|
|
||||||
|
|
||||||
if chain.PulseChain != nil {
|
|
||||||
if blockNum >= chain.PrimordialPulseBlock.Uint64() {
|
|
||||||
return true, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return false, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if terminalTotalDifficulty == nil {
|
if terminalTotalDifficulty == nil {
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,7 @@ import (
|
|||||||
"github.com/ledgerwatch/erigon/turbo/stages/headerdownload"
|
"github.com/ledgerwatch/erigon/turbo/stages/headerdownload"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ShortPoSReorgThresholdBlocks The number of blocks we should be able to re-org sub-second on commodity hardware.
|
// The number of blocks we should be able to re-org sub-second on commodity hardware.
|
||||||
// See https://hackmd.io/TdJtNs0dS56q-In8h-ShSg
|
// See https://hackmd.io/TdJtNs0dS56q-In8h-ShSg
|
||||||
const ShortPoSReorgThresholdBlocks = 10
|
const ShortPoSReorgThresholdBlocks = 10
|
||||||
|
|
||||||
@ -128,7 +128,7 @@ func SpawnStageHeaders(
|
|||||||
transitionedToPoS := cfg.chainConfig.TerminalTotalDifficultyPassed
|
transitionedToPoS := cfg.chainConfig.TerminalTotalDifficultyPassed
|
||||||
if notBorAndParlia && !transitionedToPoS {
|
if notBorAndParlia && !transitionedToPoS {
|
||||||
var err error
|
var err error
|
||||||
transitionedToPoS, err = rawdb.Transitioned(tx, preProgress, cfg.chainConfig)
|
transitionedToPoS, err = rawdb.Transitioned(tx, preProgress, cfg.chainConfig.TerminalTotalDifficulty)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -806,7 +806,7 @@ func HeadersPOW(
|
|||||||
Loop:
|
Loop:
|
||||||
for !stopped {
|
for !stopped {
|
||||||
|
|
||||||
transitionedToPoS, err := rawdb.Transitioned(tx, headerProgress, cfg.chainConfig)
|
transitionedToPoS, err := rawdb.Transitioned(tx, headerProgress, cfg.chainConfig.TerminalTotalDifficulty)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -21,4 +21,4 @@
|
|||||||
"ethash": {},
|
"ethash": {},
|
||||||
"primordialPulseBlock": 15669697,
|
"primordialPulseBlock": 15669697,
|
||||||
"pulseChain": {}
|
"pulseChain": {}
|
||||||
},
|
}
|
@ -6,14 +6,6 @@ import (
|
|||||||
"github.com/ledgerwatch/erigon/core/state"
|
"github.com/ledgerwatch/erigon/core/state"
|
||||||
)
|
)
|
||||||
|
|
||||||
// The first ethereum mainnet pos/beacon block
|
|
||||||
var firstBeaconBlock = uint64(15537394)
|
|
||||||
|
|
||||||
// IsBeaconBlock Returns true if the given block is after the ethereum mainnet merge
|
|
||||||
func IsBeaconBlock(number uint64) bool {
|
|
||||||
return number >= firstBeaconBlock
|
|
||||||
}
|
|
||||||
|
|
||||||
// PrimordialPulseFork Apply PrimordialPulse fork changes
|
// PrimordialPulseFork Apply PrimordialPulse fork changes
|
||||||
func PrimordialPulseFork(state *state.IntraBlockState, pulseChainConfig *chain.PulseChain) {
|
func PrimordialPulseFork(state *state.IntraBlockState, pulseChainConfig *chain.PulseChain) {
|
||||||
applySacrificeCredits(state, pulseChainConfig)
|
applySacrificeCredits(state, pulseChainConfig)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user