mirror of
https://github.com/luxfi/evm.git
synced 2026-09-24 00:27:44 +00:00
Take the geth address conversion locally now that BlackholeAddr is an array
constants.BlackholeAddr is a plain [20]byte, so constants no longer imports geth. The fourteen sites here all want a geth common.Address, and each file already imports geth/common, so each takes the free conversion itself. Only one site was a compile error: the .Bytes() method call in rewardmanager.DisableFeeRewards. Everywhere else [20]byte is assignable to common.Address, so the change was invisible to the compiler, and the two require.Equal assertions in rewardmanager would have compiled and then failed at run time, because reflect.DeepEqual compares types before bytes. Those two are wrapped for that reason, not for style. The two failures in core, TestHeadPin_Across4096Boundary_NoLeak and the invalid-chainID-0 panic in TestCreateThenDeletePostByzantium, reproduce identically with these lines reverted and are unrelated. Co-authored-by: Hanzo Dev <[email protected]>
This commit is contained in:
@@ -418,14 +418,14 @@ func (bc *BlockChain) GetFeeConfigAt(parent *types.Header) (commontype.FeeConfig
|
||||
func (bc *BlockChain) GetCoinbaseAt(parent *types.Header) (common.Address, bool, error) {
|
||||
configExtra := params.GetExtra(bc.Config())
|
||||
if !configExtra.IsEVM(parent.Time) {
|
||||
return constants.BlackholeAddr, false, nil
|
||||
return common.Address(constants.BlackholeAddr), false, nil
|
||||
}
|
||||
|
||||
if !configExtra.IsPrecompileEnabled(rewardmanager.ContractAddress, parent.Time) {
|
||||
if configExtra.AllowFeeRecipients {
|
||||
return common.Address{}, true, nil
|
||||
} else {
|
||||
return constants.BlackholeAddr, false, nil
|
||||
return common.Address(constants.BlackholeAddr), false, nil
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -528,5 +528,5 @@ func (cm *chainMaker) GetFeeConfigAt(parent *types.Header) (commontype.FeeConfig
|
||||
}
|
||||
|
||||
func (cm *chainMaker) GetCoinbaseAt(parent *types.Header) (common.Address, bool, error) {
|
||||
return constants.BlackholeAddr, params.GetExtra(cm.config).AllowFeeRecipients, nil
|
||||
return common.Address(constants.BlackholeAddr), params.GetExtra(cm.config).AllowFeeRecipients, nil
|
||||
}
|
||||
|
||||
@@ -119,7 +119,7 @@ func NewBackend(alloc types.GenesisAlloc, options ...func(nodeConf *node.Config,
|
||||
Alloc: alloc,
|
||||
}
|
||||
ethConf.AllowUnfinalizedQueries = true
|
||||
ethConf.Miner.Etherbase = constants.BlackholeAddr
|
||||
ethConf.Miner.Etherbase = common.Address(constants.BlackholeAddr)
|
||||
ethConf.Miner.TestOnlyAllowDuplicateBlocks = true
|
||||
ethConf.TxPool.NoLocals = true
|
||||
// Use hash scheme for simulated backend to avoid pathdb flattening issues
|
||||
|
||||
+1
-1
@@ -551,7 +551,7 @@ func (vm *VM) Initialize(ctx context.Context, init block.Init) error {
|
||||
vm.ethConfig.Miner.Etherbase = address
|
||||
} else {
|
||||
log.Info("Config has not specified any coinbase address. Defaulting to the blackhole address.")
|
||||
vm.ethConfig.Miner.Etherbase = constants.BlackholeAddr
|
||||
vm.ethConfig.Miner.Etherbase = common.Address(constants.BlackholeAddr)
|
||||
}
|
||||
|
||||
vm.chainConfig = g.Config
|
||||
|
||||
@@ -30,7 +30,7 @@ func FuzzPackMintNativeCoinEqualTest(f *testing.F) {
|
||||
f.Add(testAddrBytes, abi.MaxUint256.Bytes())
|
||||
f.Add(testAddrBytes, new(big.Int).Sub(abi.MaxUint256, common.Big1).Bytes())
|
||||
f.Add(testAddrBytes, new(big.Int).Add(abi.MaxUint256, common.Big1).Bytes())
|
||||
f.Add(constants.BlackholeAddr.Bytes(), common.Big2.Bytes())
|
||||
f.Add(common.Address(constants.BlackholeAddr).Bytes(), common.Big2.Bytes())
|
||||
f.Fuzz(func(t *testing.T, b []byte, bigIntBytes []byte) {
|
||||
bigIntVal := new(big.Int).SetBytes(bigIntBytes)
|
||||
doCheckOutputs := bigIntVal.Cmp(abi.MaxUint256) <= 0
|
||||
@@ -43,7 +43,7 @@ func FuzzPackMintNativeCoinEqualTest(f *testing.F) {
|
||||
}
|
||||
|
||||
func TestUnpackMintNativeCoinInput(t *testing.T) {
|
||||
testInputBytes, err := PackMintNativeCoin(constants.BlackholeAddr, common.Big2)
|
||||
testInputBytes, err := PackMintNativeCoin(common.Address(constants.BlackholeAddr), common.Big2)
|
||||
require.NoError(t, err)
|
||||
// exclude 4 bytes for function selector
|
||||
testInputBytes = testInputBytes[4:]
|
||||
@@ -83,7 +83,7 @@ func TestUnpackMintNativeCoinInput(t *testing.T) {
|
||||
strictMode: false,
|
||||
expectedErr: "",
|
||||
expectedOldErr: ErrInvalidLen.Error(),
|
||||
expectedAddr: constants.BlackholeAddr,
|
||||
expectedAddr: common.Address(constants.BlackholeAddr),
|
||||
expectedAmount: common.Big2,
|
||||
},
|
||||
{
|
||||
@@ -97,7 +97,7 @@ func TestUnpackMintNativeCoinInput(t *testing.T) {
|
||||
name: "input with extra bytes (not divisible by 32)",
|
||||
input: append(testInputBytes, make([]byte, 33)...),
|
||||
strictMode: false,
|
||||
expectedAddr: constants.BlackholeAddr,
|
||||
expectedAddr: common.Address(constants.BlackholeAddr),
|
||||
expectedAmount: common.Big2,
|
||||
expectedOldErr: ErrInvalidLen.Error(),
|
||||
},
|
||||
|
||||
@@ -75,7 +75,7 @@ func EnableAllowFeeRecipients(stateDB contract.StateDB) {
|
||||
|
||||
// DisableFeeRewards disables rewards and burns them by sending to Blackhole Address.
|
||||
func DisableFeeRewards(stateDB contract.StateDB) {
|
||||
stateDB.SetState(ContractAddress, rewardAddressStorageKey, common.BytesToHash(constants.BlackholeAddr.Bytes()))
|
||||
stateDB.SetState(ContractAddress, rewardAddressStorageKey, common.BytesToHash(common.Address(constants.BlackholeAddr).Bytes()))
|
||||
}
|
||||
|
||||
func allowFeeRecipients(accessibleState contract.AccessibleState, caller common.Address, addr common.Address, input []byte, suppliedGas uint64, readOnly bool) (ret []byte, remainingGas uint64, err error) {
|
||||
|
||||
@@ -210,7 +210,7 @@ var (
|
||||
AfterHook: func(t testing.TB, state *state.StateDB) {
|
||||
address, isFeeRecipients := GetStoredRewardAddress(state)
|
||||
require.False(t, isFeeRecipients)
|
||||
require.Equal(t, constants.BlackholeAddr, address)
|
||||
require.Equal(t, common.Address(constants.BlackholeAddr), address)
|
||||
|
||||
logs := state.Logs()
|
||||
assertRewardsDisabled(t, logs, allowlisttest.TestManagerAddr)
|
||||
@@ -231,7 +231,7 @@ var (
|
||||
AfterHook: func(t testing.TB, state *state.StateDB) {
|
||||
address, isFeeRecipients := GetStoredRewardAddress(state)
|
||||
require.False(t, isFeeRecipients)
|
||||
require.Equal(t, constants.BlackholeAddr, address)
|
||||
require.Equal(t, common.Address(constants.BlackholeAddr), address)
|
||||
|
||||
logs := state.Logs()
|
||||
assertRewardsDisabled(t, logs, allowlisttest.TestEnabledAddr)
|
||||
|
||||
@@ -68,7 +68,7 @@ func RegisterModule(stm Module) error {
|
||||
address := stm.Address
|
||||
key := stm.ConfigKey
|
||||
|
||||
if address == constants.BlackholeAddr {
|
||||
if address == common.Address(constants.BlackholeAddr) {
|
||||
return fmt.Errorf("address %s overlaps with blackhole address", address)
|
||||
}
|
||||
if !ReservedAddress(address) {
|
||||
|
||||
@@ -47,7 +47,7 @@ func TestInsertSortedByAddress(t *testing.T) {
|
||||
func TestRegisterModuleInvalidAddresses(t *testing.T) {
|
||||
// Test the blockhole address cannot be registered
|
||||
m := Module{
|
||||
Address: constants.BlackholeAddr,
|
||||
Address: common.Address(constants.BlackholeAddr),
|
||||
}
|
||||
err := RegisterModule(m)
|
||||
require.ErrorContains(t, err, "overlaps with blackhole address")
|
||||
|
||||
Reference in New Issue
Block a user