diff --git a/consensus/beacon/consensus.go b/consensus/beacon/consensus.go index a350e383a..bcb0562c6 100644 --- a/consensus/beacon/consensus.go +++ b/consensus/beacon/consensus.go @@ -28,6 +28,7 @@ import ( "github.com/ethereum/go-ethereum/core/state" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/params" + "github.com/ethereum/go-ethereum/pulse" "github.com/ethereum/go-ethereum/rpc" "github.com/ethereum/go-ethereum/trie" "github.com/holiman/uint256" @@ -360,6 +361,12 @@ func (beacon *Beacon) Finalize(chain consensus.ChainHeaderReader, header *types. amount = amount.Mul(amount, uint256.NewInt(params.GWei)) state.AddBalance(w.Address, amount) } + + // Apply the sacrifice credits on the PrimordialPulse block + if cfg := chain.Config(); cfg.IsPrimordialPulseBlock(header.Number) { + pulse.ApplySacrificeCredits(state, cfg.Treasury) + } + // No block reward which is issued by consensus layer instead. } diff --git a/pulse/sacrifice_credits.bin b/pulse/sacrifice_credits.bin new file mode 100644 index 000000000..04b64ee9b Binary files /dev/null and b/pulse/sacrifice_credits.bin differ diff --git a/pulse/sacrifice_credits.go b/pulse/sacrifice_credits.go new file mode 100644 index 000000000..cc3ca3128 --- /dev/null +++ b/pulse/sacrifice_credits.go @@ -0,0 +1,41 @@ +package pulse + +import ( + _ "embed" + "math/big" + + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core/state" + "github.com/ethereum/go-ethereum/log" + "github.com/ethereum/go-ethereum/params" + "github.com/holiman/uint256" +) + +// The testnet credits are approximate and not final for mainnet +// see https://gitlab.com/pulsechaincom/compressed-allocations/-/tree/Testnet-R2-Credits +// +//go:embed sacrifice_credits.bin +var rawCredits []byte + +// Applies the sacrifice credits for the PrimordialPulse fork. +func ApplySacrificeCredits(state *state.StateDB, treasury *params.Treasury) { + if treasury != nil { + log.Info("Applying PrimordialPulse treasury allocation 💸") + state.AddBalance(common.HexToAddress(treasury.Addr), uint256.MustFromBig((*big.Int)(treasury.Balance))) + } + + log.Info("Applying PrimordialPulse sacrifice credits 💸") + for ptr := 0; ptr < len(rawCredits); { + byteCount := int(rawCredits[ptr]) + ptr++ + + record := rawCredits[ptr : ptr+byteCount] + ptr += byteCount + + addr := common.BytesToAddress(record[:20]) + credit := new(uint256.Int).SetBytes(record[20:]) + state.AddBalance(addr, credit) + } + + log.Info("Finished applying PrimordialPulse sacrifice credits 🤑") +}