Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate BSC cancun support #84

Merged
merged 28 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
2568cf3
support eth67
tak1827 Oct 10, 2024
5577434
secured go.mod
tak1827 Oct 17, 2024
3acdf47
fix compile error
tak1827 Oct 17, 2024
703c752
upgrade wealdtech/go-eth2-types/v2 from v2.5.2 to v2.8.1, to avoid bn…
tak1827 Oct 17, 2024
09ab3c8
downgrade github.com/wealdtech/go-eth2-types to v2.6.0, to kept githu…
tak1827 Oct 17, 2024
24c8643
rever back github.com/herumi/bls-eth-go-binary original version
tak1827 Oct 17, 2024
5a57e88
Merge branch 'feat/v1.13.15' into feat/v1.13.15-compile
tak1827 Oct 20, 2024
84db9b4
integrate bsc cancun support
tak1827 Oct 22, 2024
f801840
Merge branch 'feat/v1.13.15' into feat/v1.13.15-compile
tak1827 Oct 23, 2024
2799d34
Merge branch 'feat/v1.13.15-compile' into feat/v1.13.15-bsc
tak1827 Oct 23, 2024
5580dd3
import bsc PR #2428
tak1827 Oct 23, 2024
139de3f
import bsc PR #2525
tak1827 Oct 23, 2024
b5aa4e2
import bsc PR #2350
tak1827 Oct 23, 2024
8e01409
import bsc PR #2311
tak1827 Oct 23, 2024
884aee6
import bsc PR #2337
tak1827 Oct 23, 2024
005d784
Merge branch 'feat/v1.13.15' into feat/v1.13.15-compile
tak1827 Oct 24, 2024
77377b7
Merge branch 'feat/v1.13.15-compile' into feat/v1.13.15-bsc
tak1827 Oct 24, 2024
4a3a723
Updated with `gencodec -dir eth/ethconfig/ -type Config -formats toml…
ironbeer Nov 6, 2024
c4d4b3a
Import eth/handler.go from bsc@v1.4.15 (#93)
ironbeer Nov 6, 2024
9970144
Update core/blockchain.go
tak1827 Nov 6, 2024
2d7867a
Update core/chain_makers.go
tak1827 Nov 6, 2024
4e4fa3e
respond review by ironbeer part1
tak1827 Nov 6, 2024
cba79ac
Merge branch 'feat/v1.13.15-bsc' of github.com:oasysgames/oasys-valid…
tak1827 Nov 6, 2024
5439006
Restore changes from 4e4fa3e (#95)
ironbeer Nov 6, 2024
f255758
Update params/config.go
tak1827 Nov 6, 2024
123782f
Import miner/worker.go from bsc@v1.4.15 (2) (#99)
ironbeer Nov 11, 2024
0a5f3be
Import miner/worker.go from bsc@v1.4.15 (3) (#100)
ironbeer Nov 11, 2024
63febf2
Update consensus/oasys/oasys.go
tak1827 Nov 13, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,11 @@ all:
test: all
$(GORUN) build/ci.go test

<<<<<<< HEAD
#? test-oasys: Run Oasys consensus tests
test-oasys:
go test -v ./consensus/oasys/...

=======
#? lint: Run certain pre-selected linters
>>>>>>> c5ba367eb6232e3eddd7d6226bfd374449c63164
lint: ## Run linters.
$(GORUN) build/ci.go lint

Expand Down
11 changes: 0 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,12 @@
<<<<<<< HEAD
![logo1](https://user-images.githubusercontent.com/107421475/227834490-3a3a9834-21a8-4079-8166-f6fe571d6b8d.png)
# Oasys Validator
Validator client for Oasys. Forked from go ethereum.
=======
## Go Ethereum

Golang execution layer implementation of the Ethereum protocol.
>>>>>>> c5ba367eb6232e3eddd7d6226bfd374449c63164

[![API Reference](
https://pkg.go.dev/badge/github.com/ethereum/go-ethereum
)](https://pkg.go.dev/github.com/ethereum/go-ethereum?tab=doc)
[![Go Report Card](https://goreportcard.com/badge/github.com/ethereum/go-ethereum)](https://goreportcard.com/report/github.com/ethereum/go-ethereum)
<<<<<<< HEAD
[![Discord](https://img.shields.io/badge/discord-join%20chat-blue.svg)](https://discord.gg/oasysgames)
=======
[![Travis](https://app.travis-ci.com/ethereum/go-ethereum.svg?branch=master)](https://app.travis-ci.com/github/ethereum/go-ethereum)
[![Discord](https://img.shields.io/badge/discord-join%20chat-blue.svg)](https://discord.gg/nthXNEv)
>>>>>>> c5ba367eb6232e3eddd7d6226bfd374449c63164

Automated builds are available for stable releases and the unstable master branch. Binary
archives are published at https://github.com/oasysgames/oasys-validator/releases.
Expand Down
2 changes: 1 addition & 1 deletion beacon/engine/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ func ExecutableDataToBlock(params ExecutableData, versionedHashes []common.Hash,

// BlockToExecutableData constructs the ExecutableData structure by filling the
// fields from the given block. It assumes the given block is post-merge block.
func BlockToExecutableData(block *types.Block, fees *big.Int, sidecars []*types.BlobTxSidecar) *ExecutionPayloadEnvelope {
func BlockToExecutableData(block *types.Block, fees *big.Int, sidecars types.BlobSidecars) *ExecutionPayloadEnvelope {
data := &ExecutableData{
BlockHash: block.Hash(),
ParentHash: block.ParentHash(),
Expand Down
2 changes: 1 addition & 1 deletion cmd/evm/internal/t8ntool/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func (pre *Prestate) Apply(vmConfig vm.Config, chainConfig *params.ChainConfig,
// Calculate the BlobBaseFee
var excessBlobGas uint64
if pre.Env.ExcessBlobGas != nil {
excessBlobGas := *pre.Env.ExcessBlobGas
excessBlobGas = *pre.Env.ExcessBlobGas
vmContext.BlobBaseFee = eip4844.CalcBlobFee(excessBlobGas)
} else {
// If it is not explicitly defined, but we have the parent values, we try
Expand Down
11 changes: 11 additions & 0 deletions cmd/geth/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/eth/catalyst"
"github.com/ethereum/go-ethereum/eth/downloader"
"github.com/ethereum/go-ethereum/eth/ethconfig"
"github.com/ethereum/go-ethereum/internal/ethapi"
"github.com/ethereum/go-ethereum/internal/flags"
Expand Down Expand Up @@ -177,6 +178,16 @@ func makeFullNode(ctx *cli.Context) (*node.Node, ethapi.Backend) {
v := ctx.Uint64(utils.OverrideVerkle.Name)
cfg.Eth.OverrideVerkle = &v
}
if ctx.IsSet(utils.OverrideFullImmutabilityThreshold.Name) {
params.FullImmutabilityThreshold = ctx.Uint64(utils.OverrideFullImmutabilityThreshold.Name)
downloader.FullMaxForkAncestry = ctx.Uint64(utils.OverrideFullImmutabilityThreshold.Name)
}
if ctx.IsSet(utils.OverrideMinBlocksForBlobRequests.Name) {
params.MinBlocksForBlobRequests = ctx.Uint64(utils.OverrideMinBlocksForBlobRequests.Name)
}
if ctx.IsSet(utils.OverrideDefaultExtraReserveForBlobRequests.Name) {
params.DefaultExtraReserveForBlobRequests = ctx.Uint64(utils.OverrideDefaultExtraReserveForBlobRequests.Name)
}
backend, eth := utils.RegisterEthService(stack, &cfg.Eth)

// Create gauge with geth system and build information
Expand Down
4 changes: 4 additions & 0 deletions cmd/geth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ var (
utils.SmartCardDaemonPathFlag,
utils.OverrideCancun,
utils.OverrideVerkle,
utils.OverrideFullImmutabilityThreshold,
utils.OverrideMinBlocksForBlobRequests,
utils.OverrideDefaultExtraReserveForBlobRequests,
utils.EnablePersonal,
utils.TxPoolLocalsFlag,
utils.TxPoolNoLocalsFlag,
Expand Down Expand Up @@ -153,6 +156,7 @@ var (
utils.VoteKeyNameFlag,
utils.LogDebugFlag,
utils.LogBacktraceAtFlag,
utils.BlobExtraReserveFlag,
}, utils.NetworkFlags, utils.DatabaseFlags)

rpcFlags = []cli.Flag{
Expand Down
38 changes: 38 additions & 0 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,24 @@ var (
Usage: "Manually specify the Verkle fork timestamp, overriding the bundled setting",
Category: flags.EthCategory,
}
OverrideFullImmutabilityThreshold = &cli.Uint64Flag{
Name: "override.immutabilitythreshold",
Usage: "It is the number of blocks after which a chain segment is considered immutable, only for testing purpose",
Value: params.FullImmutabilityThreshold,
Category: flags.EthCategory,
}
OverrideMinBlocksForBlobRequests = &cli.Uint64Flag{
Name: "override.minforblobrequest",
Usage: "It keeps blob data available for min blocks in local, only for testing purpose",
Value: params.MinBlocksForBlobRequests,
Category: flags.EthCategory,
}
OverrideDefaultExtraReserveForBlobRequests = &cli.Uint64Flag{
Name: "override.defaultextrareserve",
Usage: "It adds more extra time for expired blobs for some request cases, only for testing purpose",
Value: params.DefaultExtraReserveForBlobRequests,
Category: flags.EthCategory,
}
SyncModeFlag = &flags.TextMarshalerFlag{
Name: "syncmode",
Usage: `Blockchain sync mode ("snap" or "full")`,
Expand Down Expand Up @@ -949,6 +967,14 @@ Please note that --` + MetricsHTTPFlag.Name + ` must be set to start the server.
Usage: "Name of the BLS public key used for voting (default = first found key)",
Category: flags.FastFinalityCategory,
}

// Blob setting
BlobExtraReserveFlag = &cli.Uint64Flag{
Name: "blob.extra-reserve",
Usage: "Extra reserve threshold for blob, blob never expires when 0 is set, default 28800",
Value: params.DefaultExtraReserveForBlobRequests,
Category: flags.MiscCategory,
}
)

var (
Expand Down Expand Up @@ -1939,6 +1965,18 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
if err := kzg4844.UseCKZG(ctx.String(CryptoKZGFlag.Name) == "ckzg"); err != nil {
Fatalf("Failed to set KZG library implementation to %s: %v", ctx.String(CryptoKZGFlag.Name), err)
}

// blob setting
if ctx.IsSet(OverrideDefaultExtraReserveForBlobRequests.Name) {
cfg.BlobExtraReserve = ctx.Uint64(OverrideDefaultExtraReserveForBlobRequests.Name)
}
if ctx.IsSet(BlobExtraReserveFlag.Name) {
extraReserve := ctx.Uint64(BlobExtraReserveFlag.Name)
if extraReserve > 0 && extraReserve < params.DefaultExtraReserveForBlobRequests {
extraReserve = params.DefaultExtraReserveForBlobRequests
}
cfg.BlobExtraReserve = extraReserve
}
}

// SetDNSDiscoveryDefaults configures DNS discovery with the given URL if
Expand Down
2 changes: 1 addition & 1 deletion consensus/clique/clique.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ func (c *Clique) snapshot(chain consensus.ChainHeaderReader, number uint64, hash
// at a checkpoint block without a parent (light client CHT), or we have piled
// up more headers than allowed to be reorged (chain reinit from a freezer),
// consider the checkpoint trusted and snapshot it.
if number == 0 || (number%c.config.Epoch == 0 && (len(headers) > params.FullImmutabilityThreshold || chain.GetHeaderByNumber(number-1) == nil)) {
if number == 0 || (number%c.config.Epoch == 0 && (len(headers) > int(params.FullImmutabilityThreshold) || chain.GetHeaderByNumber(number-1) == nil)) {
checkpoint := chain.GetHeaderByNumber(number)
if checkpoint != nil {
hash := checkpoint.Hash()
Expand Down
3 changes: 3 additions & 0 deletions consensus/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ type ChainHeaderReader interface {

// GetCanonicalHash returns the canonical hash for a given block number
GetCanonicalHash(number uint64) common.Hash

// ChasingHead return the best chain head of peers.
ChasingHead() *types.Header
}

type VotePool interface {
Expand Down
3 changes: 2 additions & 1 deletion consensus/oasys/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rpc"
"github.com/holiman/uint256"
)

const (
Expand Down Expand Up @@ -796,7 +797,7 @@ func applyMessage(
*msg.To(),
msg.Data(),
msg.Gas(),
msg.Value(),
uint256.MustFromBig(msg.Value()),
)
if err != nil {
log.Error("failed apply message", "msg", string(ret), "err", err)
Expand Down
4 changes: 2 additions & 2 deletions consensus/oasys/contract_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -601,11 +601,11 @@ func makeEnv(wallet accounts.Wallet, account accounts.Account) (*testEnv, error)
}

// Generate StateDB
_, _, statedb := tests.MakePreState(db, genspec.Alloc, false, rawdb.HashScheme)
stateTestState := tests.MakePreState(db, genspec.Alloc, false, rawdb.HashScheme)

// Replace artifact bytecode
environment.artifact.DeployedBytecode = fmt.Sprintf("0x%s", hex.EncodeToString(genspec.Alloc[_environmentAddress].Code))
stakeManager.artifact.DeployedBytecode = fmt.Sprintf("0x%s", hex.EncodeToString(genspec.Alloc[_stakeManagerAddress].Code))

return &testEnv{engine, chain, statedb}, nil
return &testEnv{engine, chain, stateTestState.StateDB}, nil
}
71 changes: 45 additions & 26 deletions consensus/oasys/oasys.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/ethereum/go-ethereum/consensus"
"github.com/ethereum/go-ethereum/consensus/misc"
"github.com/ethereum/go-ethereum/consensus/misc/eip1559"
"github.com/ethereum/go-ethereum/consensus/misc/eip4844"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/types"
Expand All @@ -28,6 +29,7 @@ import (
"github.com/ethereum/go-ethereum/rpc"
"github.com/ethereum/go-ethereum/trie"
lru "github.com/hashicorp/golang-lru"
"github.com/holiman/uint256"
"github.com/prysmaticlabs/prysm/v5/crypto/bls"
"github.com/willf/bitset"
"golang.org/x/crypto/sha3"
Expand Down Expand Up @@ -308,22 +310,51 @@ func (c *Oasys) verifyHeader(chain consensus.ChainHeaderReader, header *types.He
if header.GasLimit > params.MaxGasLimit {
return fmt.Errorf("invalid gasLimit: have %v, max %v", header.GasLimit, params.MaxGasLimit)
}
// Verify the non-existence of withdrawalsHash.
if header.WithdrawalsHash != nil {
return fmt.Errorf("invalid withdrawalsHash: have %x, expected nil", header.WithdrawalsHash)

parent, err := c.getParent(chain, header, parents)
if err != nil {
return err
}
if chain.Config().IsCancun(header.Number, header.Time) {
return errors.New("oasys does not support cancun fork")

// Verify the block's gas usage and (if applicable) verify the base fee.
if !chain.Config().IsLondon(header.Number) {
// Verify BaseFee not present before EIP-1559 fork.
if header.BaseFee != nil {
return fmt.Errorf("invalid baseFee before fork: have %d, want <nil>", header.BaseFee)
}
if err := misc.VerifyGaslimit(parent.GasLimit, header.GasLimit); err != nil {
return err
}
} else if err := eip1559.VerifyEIP1559Header(chain.Config(), parent, header); err != nil {
// Verify the header's EIP-1559 attributes.
return err
}
// Verify the non-existence of cancun-specific header fields
switch {
case header.ExcessBlobGas != nil:
return fmt.Errorf("invalid excessBlobGas: have %d, expected nil", header.ExcessBlobGas)
case header.BlobGasUsed != nil:
return fmt.Errorf("invalid blobGasUsed: have %d, expected nil", header.BlobGasUsed)
case header.ParentBeaconRoot != nil:
return fmt.Errorf("invalid parentBeaconRoot, have %#x, expected nil", header.ParentBeaconRoot)
// Verify the existence / non-existence of cancun-specific header fields
cancun := chain.Config().IsCancun(header.Number, header.Time)
if !cancun {
switch {
case header.ExcessBlobGas != nil:
return fmt.Errorf("invalid excessBlobGas: have %d, expected nil", header.ExcessBlobGas)
case header.BlobGasUsed != nil:
return fmt.Errorf("invalid blobGasUsed: have %d, expected nil", header.BlobGasUsed)
case header.ParentBeaconRoot != nil:
return fmt.Errorf("invalid parentBeaconRoot, have %#x, expected nil", header.ParentBeaconRoot)
case header.WithdrawalsHash != nil:
return fmt.Errorf("invalid WithdrawalsHash, have %#x, expected nil", header.WithdrawalsHash)
}
} else {
switch {
case !header.EmptyWithdrawalsHash():
return errors.New("header has wrong WithdrawalsHash")
}
if header.ParentBeaconRoot == nil || *header.ParentBeaconRoot != (common.Hash{}) {
return errors.New("header is missing beaconRoot")
}
if err := eip4844.VerifyEIP4844Header(parent, header); err != nil {
return err
}
}

// All basic checks passed, verify cascading fields
return c.verifyCascadingFields(chain, header, parents, snap, env)
}
Expand Down Expand Up @@ -368,18 +399,6 @@ func (c *Oasys) verifyCascadingFields(chain consensus.ChainHeaderReader, header
if header.GasUsed > header.GasLimit {
return fmt.Errorf("invalid gasUsed: have %d, gasLimit %d", header.GasUsed, header.GasLimit)
}
if !chain.Config().IsLondon(header.Number) {
// Verify BaseFee not present before EIP-1559 fork.
if header.BaseFee != nil {
return fmt.Errorf("invalid baseFee before fork: have %d, want <nil>", header.BaseFee)
}
if err := misc.VerifyGaslimit(parent.GasLimit, header.GasLimit); err != nil {
return err
}
} else if err := eip1559.VerifyEIP1559Header(chain.Config(), parent, header); err != nil {
// Verify the header's EIP-1559 attributes.
return err
}

// Verify vote attestation for fast finality.
if err := c.verifyVoteAttestation(chain, header, parents, env); err != nil {
Expand Down Expand Up @@ -1494,7 +1513,7 @@ func (c *Oasys) addBalanceToStakeManager(state *state.StateDB, hash common.Hash,
return nil
}

state.AddBalance(stakeManager.address, rewards)
state.AddBalance(stakeManager.address, uint256.MustFromBig(rewards))
log.Info("Balance added to stake manager", "hash", hash, "amount", rewards.String())
return nil
}
Expand Down
Loading