Skip to content

Commit 90619e1

Browse files
committed
feat(all): update moonchain protocol
1 parent 8ec1bd5 commit 90619e1

File tree

10 files changed

+22
-40
lines changed

10 files changed

+22
-40
lines changed

cmd/utils/flags.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1740,7 +1740,7 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
17401740
}
17411741
// Override any default configs for hard coded networks.
17421742
switch {
1743-
// CHANGE(moonchain): when --moonchain flag is set, use the Taiko genesis.
1743+
// CHANGE(moonchain): when --mxc flag is set, use the Moonchain genesis.
17441744
case ctx.IsSet(MoonchainFlag.Name):
17451745
cfg.Genesis = core.MoonchainGenesisBlock(cfg.NetworkId)
17461746
// CHANGE(taiko): when --taiko flag is set, use the Taiko genesis.

cmd/utils/moonchain_flags.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ var (
1818
}
1919
)
2020

21-
// RegisterMoonchainAPIs initializes and registers the Taiko RPC APIs.
21+
// RegisterMoonchainAPIs initializes and registers the Moonchain RPC APIs.
2222
func RegisterMoonchainAPIs(stack *node.Node, cfg *ethconfig.Config, backend *eth.Ethereum) {
2323
if os.Getenv("MOONCHAIN_TEST") != "" {
2424
return
2525
}
26-
// Add methods under "taiko_" RPC namespace to the available APIs list
26+
// Add methods under "moonchain_" RPC namespace to the available APIs list
2727
stack.RegisterAPIs([]rpc.API{
2828
{
2929
Namespace: "moonchain",

consensus/moonchain/consensus.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,6 @@ func (t *Moonchain) Finalize(chain consensus.ChainHeaderReader, header *types.He
204204
for _, w := range withdrawals {
205205
state.AddBalance(w.Address, uint256.MustFromBig(new(big.Int).SetUint64(w.Amount)))
206206
}
207-
208-
state.AddBalance(t.moonchainL2Treasury, uint256.MustFromBig(new(big.Int).SetBytes(header.Extra)))
209207
header.Root = state.IntermediateRoot(true)
210208
}
211209

core/state_processor.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg
9292
if err != nil {
9393
return nil, nil, 0, fmt.Errorf("could not apply tx %d [%v]: %w", i, tx.Hash().Hex(), err)
9494
}
95+
if p.config.IsOntake(block.Number()) {
96+
msg.BasefeeSharingPctg = DecodeOntakeExtraData(header.Extra)
97+
}
9598
statedb.SetTxContext(tx.Hash(), i)
9699
receipt, err := applyTransaction(msg, p.config, gp, statedb, blockNumber, blockHash, tx, usedGas, vmenv)
97100
if err != nil {

core/state_transition.go

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -470,27 +470,19 @@ func (st *StateTransition) TransitionDb() (*ExecutionResult, error) {
470470
fee := new(uint256.Int).SetUint64(st.gasUsed())
471471
fee.Mul(fee, effectiveTipU256)
472472
st.state.AddBalance(st.evm.Context.Coinbase, fee)
473-
// CHANGE(moonchain): basefee is not burnt, but sent to a treasury and block.coinbase instead.
474-
// TODO: moonchain protocol update
475-
if st.evm.ChainConfig().Mxc && st.evm.Context.BaseFee != nil && !st.msg.IsAnchor {
476-
totalFee := new(big.Int).Mul(st.evm.Context.BaseFee, new(big.Int).SetUint64(st.gasUsed()))
477-
feeCoinbase := new(big.Int).Div(
478-
new(big.Int).Mul(totalFee, new(big.Int).SetUint64(uint64(st.msg.BasefeeSharingPctg))),
479-
new(big.Int).SetUint64(100),
480-
)
481-
feeTreasury := new(big.Int).Sub(totalFee, feeCoinbase)
482-
st.state.AddBalance(st.getMoonchainTreasuryAddress(), uint256.MustFromBig(feeTreasury))
483-
st.state.AddBalance(st.evm.Context.Coinbase, uint256.MustFromBig(feeCoinbase))
484-
}
485473
// CHANGE(taiko): basefee is not burnt, but sent to a treasury and block.coinbase instead.
486-
if st.evm.ChainConfig().Taiko && st.evm.Context.BaseFee != nil && !st.msg.IsAnchor {
474+
if (st.evm.ChainConfig().Taiko || st.evm.ChainConfig().Mxc) && st.evm.Context.BaseFee != nil && !st.msg.IsAnchor {
487475
totalFee := new(big.Int).Mul(st.evm.Context.BaseFee, new(big.Int).SetUint64(st.gasUsed()))
488476
feeCoinbase := new(big.Int).Div(
489477
new(big.Int).Mul(totalFee, new(big.Int).SetUint64(uint64(st.msg.BasefeeSharingPctg))),
490478
new(big.Int).SetUint64(100),
491479
)
492480
feeTreasury := new(big.Int).Sub(totalFee, feeCoinbase)
493-
st.state.AddBalance(st.getTreasuryAddress(), uint256.MustFromBig(feeTreasury))
481+
if st.evm.ChainConfig().Mxc {
482+
st.state.AddBalance(st.getMoonchainTreasuryAddress(), uint256.MustFromBig(feeTreasury))
483+
} else {
484+
st.state.AddBalance(st.getTreasuryAddress(), uint256.MustFromBig(feeTreasury))
485+
}
494486
st.state.AddBalance(st.evm.Context.Coinbase, uint256.MustFromBig(feeCoinbase))
495487
}
496488
}

eth/catalyst/api.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ func (api *ConsensusAPI) NewPayloadV2(params engine.ExecutableData) (engine.Payl
554554
}
555555
if api.eth.BlockChain().Config().LatestFork(params.Timestamp) == forks.Shanghai {
556556
if params.Withdrawals == nil &&
557-
(api.eth.BlockChain().Config().Taiko && params.WithdrawalsHash == (common.Hash{})) {
557+
(api.eth.BlockChain().Config().Taiko || api.eth.BlockChain().Config().Mxc) && params.WithdrawalsHash == (common.Hash{}) {
558558
return engine.PayloadStatusV1{Status: engine.INVALID}, engine.InvalidParams.With(errors.New("nil withdrawals post-shanghai"))
559559
}
560560
} else {

eth/ethconfig/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ type Config struct {
167167
// Clique is allowed for now to live standalone, but ethash is forbidden and can
168168
// only exist on already merged networks.
169169
func CreateConsensusEngine(config *params.ChainConfig, db ethdb.Database) (consensus.Engine, error) {
170-
// CHANGE(moonchain): use Mxc consesus engine when the --moonchain flag is set
170+
// CHANGE(moonchain): use Mxc consesus engine when the --mxc flag is set
171171
if config.Mxc {
172172
return moonchain.New(config), nil
173173
}

eth/state_accessor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ func (eth *Ethereum) stateAtTransaction(ctx context.Context, block *types.Block,
239239
// Recompute transactions up to the target index.
240240
signer := types.MakeSigner(eth.blockchain.Config(), block.Number(), block.Time())
241241
for idx, tx := range block.Transactions() {
242-
if idx == 0 && eth.config.Genesis.Config.Taiko {
242+
if idx == 0 && (eth.config.Genesis.Config.Taiko || eth.config.Genesis.Config.Mxc) {
243243
if err := tx.MarkAsAnchor(); err != nil {
244244
return nil, vm.BlockContext{}, nil, nil, err
245245
}

eth/tracers/api.go

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ func (api *API) traceChain(start, end *types.Block, config *TraceConfig, closed
270270
)
271271
// Trace all the transactions contained within
272272
for i, tx := range task.block.Transactions() {
273-
if i == 0 && api.backend.ChainConfig().Taiko {
273+
if i == 0 && (api.backend.ChainConfig().Taiko || api.backend.ChainConfig().Mxc) {
274274
if err := tx.MarkAsAnchor(); err != nil {
275275
log.Warn("Mark anchor transaction error", "error", err)
276276
task.results[i] = &txTraceResult{TxHash: tx.Hash(), Error: err.Error()}
@@ -534,7 +534,7 @@ func (api *API) IntermediateRoots(ctx context.Context, hash common.Hash, config
534534
deleteEmptyObjects = chainConfig.IsEIP158(block.Number())
535535
)
536536
for i, tx := range block.Transactions() {
537-
if i == 0 && chainConfig.Taiko {
537+
if i == 0 && (chainConfig.Taiko || chainConfig.Mxc) {
538538
if err := tx.MarkAsAnchor(); err != nil {
539539
return nil, err
540540
}
@@ -616,7 +616,7 @@ func (api *API) traceBlock(ctx context.Context, block *types.Block, config *Trac
616616
results = make([]*txTraceResult, len(txs))
617617
)
618618
for i, tx := range txs {
619-
if i == 0 && api.backend.ChainConfig().Taiko {
619+
if i == 0 && (api.backend.ChainConfig().Taiko || api.backend.ChainConfig().Mxc) {
620620
if err := tx.MarkAsAnchor(); err != nil {
621621
return nil, err
622622
}
@@ -660,14 +660,8 @@ func (api *API) traceBlockParallel(ctx context.Context, block *types.Block, stat
660660
}
661661

662662
// CHANGE(moonchain): mark the first transaction as anchor transaction.
663-
if len(txs) > 0 && api.backend.ChainConfig().Mxc {
664-
if err := txs[0].MarkAsAnchor(); err != nil {
665-
return nil, err
666-
}
667-
}
668-
669663
// CHANGE(taiko): mark the first transaction as anchor transaction.
670-
if len(txs) > 0 && api.backend.ChainConfig().Taiko {
664+
if len(txs) > 0 && (api.backend.ChainConfig().Taiko || api.backend.ChainConfig().Mxc) {
671665
if err := txs[0].MarkAsAnchor(); err != nil {
672666
return nil, err
673667
}
@@ -789,7 +783,7 @@ func (api *API) standardTraceBlockToFile(ctx context.Context, block *types.Block
789783
chainConfig, canon = overrideConfig(chainConfig, config.Overrides)
790784
}
791785
for i, tx := range block.Transactions() {
792-
if i == 0 && chainConfig.Taiko {
786+
if i == 0 && (chainConfig.Taiko || chainConfig.Mxc) {
793787
if err := tx.MarkAsAnchor(); err != nil {
794788
return nil, err
795789
}

miner/worker.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -959,12 +959,7 @@ func (w *worker) prepareWork(genParams *generateParams) (*environment, error) {
959959
if parent.Time >= timestamp {
960960
// CHANGE(taiko): block.timestamp == parent.timestamp is allowed in Taiko protocol.
961961
// CHANGE(moonchain): block.timestamp == parent.timestamp is allowed in Mxc protocol.
962-
if !w.chainConfig.Mxc {
963-
if genParams.forceTime {
964-
return nil, fmt.Errorf("invalid timestamp, parent %d given %d", parent.Time, timestamp)
965-
}
966-
timestamp = parent.Time + 1
967-
} else if !w.chainConfig.Taiko {
962+
if !w.chainConfig.Taiko && !w.chainConfig.Mxc {
968963
if genParams.forceTime {
969964
return nil, fmt.Errorf("invalid timestamp, parent %d given %d", parent.Time, timestamp)
970965
}
@@ -993,7 +988,7 @@ func (w *worker) prepareWork(genParams *generateParams) (*environment, error) {
993988
}
994989
// Set baseFee and GasLimit if we are on an EIP-1559 chain
995990
if w.chainConfig.IsLondon(header.Number) {
996-
if w.chainConfig.Taiko && genParams.baseFeePerGas != nil {
991+
if (w.chainConfig.Taiko || w.chainConfig.Mxc) && genParams.baseFeePerGas != nil {
997992
header.BaseFee = genParams.baseFeePerGas
998993
} else {
999994
header.BaseFee = eip1559.CalcBaseFee(w.chainConfig, parent)

0 commit comments

Comments
 (0)