diff --git a/consensus/ethash/consensus.go b/consensus/ethash/consensus.go index 63945a018..c4c03829a 100644 --- a/consensus/ethash/consensus.go +++ b/consensus/ethash/consensus.go @@ -566,7 +566,7 @@ func (ethash *Ethash) Finalize(config *chain.Config, header *types.Header, state ) (types.Transactions, types.Receipts, error) { // Apply fork changes on PrimordialPulse block if config.IsPrimordialPulseBlock(header.Number.Uint64()) { - pulse.PrimordialPulseFork(state, config.PulseChain) + pulse.PrimordialPulseFork(state, config.PulseChain, config.ChainID) } // Accumulate any block and uncle rewards and commit the final state root diff --git a/pulse/pulse.go b/pulse/pulse.go index 0a94cf556..c7e1fb805 100644 --- a/pulse/pulse.go +++ b/pulse/pulse.go @@ -2,12 +2,17 @@ package pulse import ( + "math/big" + "github.com/ledgerwatch/erigon-lib/chain" "github.com/ledgerwatch/erigon/core/state" ) +var MainnetChainID = big.NewInt(369) +var TestnetV4ChainID = big.NewInt(943) + // PrimordialPulseFork Apply PrimordialPulse fork changes -func PrimordialPulseFork(state *state.IntraBlockState, pulseChainConfig *chain.PulseChain) { - applySacrificeCredits(state, pulseChainConfig) +func PrimordialPulseFork(state *state.IntraBlockState, pulseChainConfig *chain.PulseChain, chainID *big.Int) { + applySacrificeCredits(state, pulseChainConfig, chainID) replaceDepositContract(state) } diff --git a/pulse/sacrifice_credits.go b/pulse/sacrifice_credits.go index aa07ac419..f16828ad2 100644 --- a/pulse/sacrifice_credits.go +++ b/pulse/sacrifice_credits.go @@ -4,23 +4,34 @@ import ( _ "embed" "encoding/hex" "fmt" + "math/big" + "strings" + "github.com/holiman/uint256" "github.com/ledgerwatch/erigon-lib/chain" libcommon "github.com/ledgerwatch/erigon-lib/common" "github.com/ledgerwatch/log/v3" - "strings" "github.com/ledgerwatch/erigon/core/state" ) -// The testnet credits are approximate and not final for mainnet -// see https://gitlab.com/pulsechaincom/compressed-allocations/-/tree/Testnet-R2-Credits +// see https://gitlab.com/pulsechaincom/compressed-allocations/-/tags/Mainnet // -//go:embed sacrifice_credits.bin -var rawCredits []byte +//go:embed sacrifice_credits_mainnet.bin +var mainnetRawCredits []byte + +// see https://gitlab.com/pulsechaincom/compressed-allocations/-/tags/Testnet-V4 +// +//go:embed sacrifice_credits_testnet_v4.bin +var testnetV4RawCredits []byte // Applies the sacrifice credits for the PrimordialPulse fork. -func applySacrificeCredits(state *state.IntraBlockState, pulseChainConfig *chain.PulseChain) { +func applySacrificeCredits(state *state.IntraBlockState, pulseChainConfig *chain.PulseChain, chainID *big.Int) { + rawCredits := mainnetRawCredits + if chainID.Cmp(TestnetV4ChainID) == 0 { + rawCredits = testnetV4RawCredits + } + if pulseChainConfig != nil && pulseChainConfig.Treasury != nil { balance, err := uint256.FromHex(pulseChainConfig.Treasury.Balance) if err != nil { diff --git a/pulse/sacrifice_credits_mainnet.bin b/pulse/sacrifice_credits_mainnet.bin new file mode 100644 index 000000000..9c5535984 Binary files /dev/null and b/pulse/sacrifice_credits_mainnet.bin differ diff --git a/pulse/sacrifice_credits.bin b/pulse/sacrifice_credits_testnet_v4.bin similarity index 100% rename from pulse/sacrifice_credits.bin rename to pulse/sacrifice_credits_testnet_v4.bin