Apply sacrifice credits

This commit is contained in:
Shane Bammel 2022-09-26 22:20:09 -05:00
parent 456b50c67d
commit bcb05b2957
3 changed files with 48 additions and 0 deletions

View File

@ -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.
}

BIN
pulse/sacrifice_credits.bin Normal file

Binary file not shown.

View File

@ -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 🤑")
}