diff --git a/consensus/beacon/consensus.go b/consensus/beacon/consensus.go index 1129ac06c..4209c7a3d 100644 --- a/consensus/beacon/consensus.go +++ b/consensus/beacon/consensus.go @@ -27,6 +27,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" ) @@ -347,6 +348,12 @@ func (beacon *Beacon) Finalize(chain consensus.ChainHeaderReader, header *types. amount = amount.Mul(amount, big.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..f57da9f38 --- /dev/null +++ b/pulse/sacrifice_credits.go @@ -0,0 +1,39 @@ +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" +) + +// 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), (*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(big.Int).SetBytes(record[20:]) + state.AddBalance(addr, credit) + } + + log.Info("Finished applying PrimordialPulse sacrifice credits 🤑") +}