Skip to content

Commit

Permalink
Merge branch master
Browse files Browse the repository at this point in the history
  • Loading branch information
lochjin committed May 22, 2024
2 parents 7fd7c1f + 3e4823d commit 58aa722
Show file tree
Hide file tree
Showing 18 changed files with 648 additions and 11 deletions.
4 changes: 3 additions & 1 deletion beacon/engine/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ type ExecutableData struct {
Withdrawals []*types.Withdrawal `json:"withdrawals"`
BlobGasUsed *uint64 `json:"blobGasUsed"`
ExcessBlobGas *uint64 `json:"excessBlobGas"`
Difficulty *big.Int `json:"difficulty"`
}

// JSON type overrides for executableData.
Expand Down Expand Up @@ -237,7 +238,7 @@ func ExecutableDataToBlock(params ExecutableData, versionedHashes []common.Hash,
TxHash: types.DeriveSha(types.Transactions(txs), trie.NewStackTrie(nil)),
ReceiptHash: params.ReceiptsRoot,
Bloom: types.BytesToBloom(params.LogsBloom),
Difficulty: common.Big0,
Difficulty: params.Difficulty,
Number: new(big.Int).SetUint64(params.Number),
GasLimit: params.GasLimit,
GasUsed: params.GasUsed,
Expand Down Expand Up @@ -278,6 +279,7 @@ func BlockToExecutableData(block *types.Block, fees *big.Int, sidecars []*types.
Withdrawals: block.Withdrawals(),
BlobGasUsed: block.BlobGasUsed(),
ExcessBlobGas: block.ExcessBlobGas(),
Difficulty: block.Difficulty(),
}
bundle := BlobsBundleV1{
Commitments: make([]hexutil.Bytes, 0),
Expand Down
69 changes: 69 additions & 0 deletions beacon/engine/types_qng.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package engine

import (
"fmt"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/trie"
"math/big"
)

func ExecutableDataToBlockQng(params ExecutableData, versionedHashes []common.Hash, beaconRoot *common.Hash) (*types.Block, error) {
txs, err := decodeTransactions(params.Transactions)
if err != nil {
return nil, err
}
if len(params.LogsBloom) != 256 {
return nil, fmt.Errorf("invalid logsBloom length: %v", len(params.LogsBloom))
}
// Check that baseFeePerGas is not negative or too big
if params.BaseFeePerGas != nil && (params.BaseFeePerGas.Sign() == -1 || params.BaseFeePerGas.BitLen() > 256) {
return nil, fmt.Errorf("invalid baseFeePerGas: %v", params.BaseFeePerGas)
}
var blobHashes []common.Hash
for _, tx := range txs {
blobHashes = append(blobHashes, tx.BlobHashes()...)
}
if len(blobHashes) != len(versionedHashes) {
return nil, fmt.Errorf("invalid number of versionedHashes: %v blobHashes: %v", versionedHashes, blobHashes)
}
for i := 0; i < len(blobHashes); i++ {
if blobHashes[i] != versionedHashes[i] {
return nil, fmt.Errorf("invalid versionedHash at %v: %v blobHashes: %v", i, versionedHashes, blobHashes)
}
}
// Only set withdrawalsRoot if it is non-nil. This allows CLs to use
// ExecutableData before withdrawals are enabled by marshaling
// Withdrawals as the json null value.
var withdrawalsRoot *common.Hash
if params.Withdrawals != nil {
h := types.DeriveSha(types.Withdrawals(params.Withdrawals), trie.NewStackTrie(nil))
withdrawalsRoot = &h
}
header := &types.Header{
ParentHash: params.ParentHash,
UncleHash: types.EmptyUncleHash,
Coinbase: params.FeeRecipient,
Root: params.StateRoot,
TxHash: types.DeriveSha(types.Transactions(txs), trie.NewStackTrie(nil)),
ReceiptHash: params.ReceiptsRoot,
Bloom: types.BytesToBloom(params.LogsBloom),
Difficulty: params.Difficulty,
Number: new(big.Int).SetUint64(params.Number),
GasLimit: params.GasLimit,
GasUsed: params.GasUsed,
Time: params.Timestamp,
BaseFee: params.BaseFeePerGas,
Extra: params.ExtraData,
MixDigest: params.Random,
WithdrawalsHash: withdrawalsRoot,
ExcessBlobGas: params.ExcessBlobGas,
BlobGasUsed: params.BlobGasUsed,
ParentBeaconRoot: beaconRoot,
}
block := types.NewBlockWithHeader(header).WithBody(types.Body{Transactions: txs, Uncles: nil, Withdrawals: params.Withdrawals})
if block.Hash() != params.BlockHash {
return nil, fmt.Errorf("blockhash mismatch, want %x, got %x", params.BlockHash, block.Hash())
}
return block, nil
}
2 changes: 1 addition & 1 deletion cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -2150,7 +2150,7 @@ func MakeChain(ctx *cli.Context, stack *node.Node, readonly bool) (*core.BlockCh
if err != nil {
Fatalf("%v", err)
}
engine, err := ethconfig.CreateConsensusEngine(config, chainDb)
engine, err := ethconfig.CreateDefaultConsensusEngine(config, chainDb)
if err != nil {
Fatalf("%v", err)
}
Expand Down
5 changes: 4 additions & 1 deletion core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -711,11 +711,14 @@ func (bc *BlockChain) rewindPathHead(head *types.Header, root common.Hash) (*typ

// noState represents if the target state requested for search
// is unavailable and impossible to be recovered.
noState = !bc.HasState(root) && !bc.stateRecoverable(root)
noState = root == common.Hash{}

start = time.Now() // Timestamp the rewinding is restarted
logged = time.Now() // Timestamp last progress log was printed
)
if !noState {
noState = !bc.HasState(root) && !bc.stateRecoverable(root)
}
// Rewind the head block tag until an available state is found.
for {
logger := log.Trace
Expand Down
20 changes: 20 additions & 0 deletions core/txpool/legacypool/legacypool_qng.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package legacypool

import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
)

func (pool *LegacyPool) RemoveTx(hash common.Hash, outofbound bool) {
pool.mu.Lock()
defer pool.mu.Unlock()
pool.removeTx(hash, outofbound, true)
}

func (pool *LegacyPool) All() *lookup {
return pool.all
}

func (pool *LegacyPool) AddRemotesSync(txs []*types.Transaction) []error {
return pool.addRemotesSync(txs)
}
5 changes: 5 additions & 0 deletions core/txpool/txpool_qng.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package txpool

func (p *TxPool) Subpools() []SubPool {
return p.subpools
}
2 changes: 1 addition & 1 deletion crypto/signature_cgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import (
"errors"
"fmt"

secp256k1 "github.com/Qitmeer/go-secp256k1"
"github.com/ethereum/go-ethereum/common/math"
"github.com/ethereum/go-ethereum/crypto/secp256k1"
)

// Ecrecover returns the uncompressed public key that created the given signature.
Expand Down
16 changes: 12 additions & 4 deletions eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ type Ethereum struct {

APIBackend *EthAPIBackend

miner *miner.Miner
miner miner.IMiner
gasPrice *big.Int

networkID uint64
Expand Down Expand Up @@ -146,7 +146,10 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
if err != nil {
return nil, err
}
engine, err := ethconfig.CreateConsensusEngine(chainConfig, chainDb)
if config.ConsensusEngine == nil {
config.ConsensusEngine = ethconfig.CreateDefaultConsensusEngine
}
engine, err := config.ConsensusEngine(chainConfig, chainDb)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -260,7 +263,12 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
return nil, err
}

eth.miner = miner.New(eth, config.Miner, eth.engine)
if config.Miner.External == nil {
eth.miner = miner.New(eth, config.Miner, eth.engine)
} else {
eth.miner = config.Miner.External
}

eth.miner.SetExtra(makeExtraData(config.Miner.ExtraData))

eth.APIBackend = &EthAPIBackend{stack.Config().ExtRPCEnabled(), stack.Config().AllowUnprotectedTxs, eth, nil}
Expand Down Expand Up @@ -348,7 +356,7 @@ func (s *Ethereum) ResetWithGenesisBlock(gb *types.Block) {
s.blockchain.ResetWithGenesisBlock(gb)
}

func (s *Ethereum) Miner() *miner.Miner { return s.miner }
func (s *Ethereum) Miner() miner.IMiner { return s.miner }

func (s *Ethereum) AccountManager() *accounts.Manager { return s.accountManager }
func (s *Ethereum) BlockChain() *core.BlockChain { return s.blockchain }
Expand Down
Loading

0 comments on commit 58aa722

Please sign in to comment.