Skip to content

Commit

Permalink
Fix lint failure
Browse files Browse the repository at this point in the history
  • Loading branch information
ckoopmann committed Dec 4, 2023
1 parent 90a98f0 commit e0d1e28
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 96 deletions.
13 changes: 6 additions & 7 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
"sync/atomic"
"time"

"github.com/google/uuid"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/lru"
"github.com/ethereum/go-ethereum/common/mclock"
Expand All @@ -50,6 +49,7 @@ import (
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/trie"
"github.com/google/uuid"
)

var (
Expand Down Expand Up @@ -2498,7 +2498,7 @@ func (bc *BlockChain) SetBlockValidatorAndProcessorForTesting(v Validator, p Pro
func (bc *BlockChain) ValidatePayload(block *types.Block, feeRecipient common.Address, expectedProfit *big.Int, registeredGasLimit uint64, vmConfig vm.Config, start time.Time, requestId uuid.UUID) error {
header := block.Header()
if err := bc.engine.VerifyHeader(bc, header, true); err != nil {
log.Debug("VerifyHeader failed", "time_elapsed", time.Since(start), "error", err, "requestId", requestId)
log.Debug("VerifyHeader failed", "time_elapsed", time.Since(start), "error", err, "requestId", requestId)
return err
} else {
log.Debug("VerifyHeader succeeded", "time_elapsed", time.Since(start), "requestId", requestId)
Expand All @@ -2515,7 +2515,7 @@ func (bc *BlockChain) ValidatePayload(block *types.Block, feeRecipient common.Ad

parent := bc.GetHeader(block.ParentHash(), block.NumberU64()-1)
if parent == nil {
log.Debug("GetHeader(Parent) failed", "time_elapsed", time.Since(start), "error", err, "requestId", requestId)
log.Debug("GetHeader(Parent) failed", "time_elapsed", time.Since(start), "error", err, "requestId", requestId)
return errors.New("parent not found")
} else {
log.Debug("GetHeader(Parent) succeeded", "time_elapsed", time.Since(start), "requestId", requestId)
Expand Down Expand Up @@ -2553,7 +2553,7 @@ func (bc *BlockChain) ValidatePayload(block *types.Block, feeRecipient common.Ad
log.Debug("Execute transactions succeeded", "time_elapsed", time.Since(start), "requestId", requestId)
}

err = nil;
err = nil
if bc.Config().IsShanghai(header.Time) {
if header.WithdrawalsHash == nil {
err = fmt.Errorf("withdrawals hash is missing")
Expand All @@ -2569,12 +2569,11 @@ func (bc *BlockChain) ValidatePayload(block *types.Block, feeRecipient common.Ad
}
if err != nil {
log.Debug("Check Withdrawal hash failed", "time_elapsed", time.Since(start), "error", err, "requestId", requestId)
return err;
return err
} else {
log.Debug("Check Withdrawal hash succeeded", "time_elapsed", time.Since(start), "requestId", requestId)
}


if err := bc.validator.ValidateBody(block); err != nil {
log.Debug("ValidateBody failed", "time_elapsed", time.Since(start), "error", err, "requestId", requestId)
return err
Expand All @@ -2593,7 +2592,7 @@ func (bc *BlockChain) ValidatePayload(block *types.Block, feeRecipient common.Ad
balanceAfter := statedb.GetBalance(feeRecipient)
feeRecipientDiff := new(big.Int).Sub(balanceAfter, balanceBefore)

err = CheckProposerPayment(expectedProfit, feeRecipient,feeRecipientDiff, receipts, block)
err = CheckProposerPayment(expectedProfit, feeRecipient, feeRecipientDiff, receipts, block)
if err != nil {
log.Debug("CheckProposerPayment failed", "time_elapsed", time.Since(start), "error", err, "requestId", requestId)
return err
Expand Down
6 changes: 1 addition & 5 deletions eth/block-validation/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import (
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/node"
"github.com/ethereum/go-ethereum/rpc"
"github.com/google/uuid"

boostTypes "github.com/flashbots/go-boost-utils/types"
"github.com/google/uuid"
)

// Register adds catalyst APIs to the full node.
Expand Down Expand Up @@ -92,8 +92,6 @@ func (api *BlockValidationAPI) ValidateBuilderSubmissionV1(params *BuilderBlockV
return nil
}



type BuilderBlockValidationRequestV2 struct {
capellaapi.SubmitBlockRequest
RegisteredGasLimit uint64 `json:"registered_gas_limit,string"`
Expand Down Expand Up @@ -140,7 +138,6 @@ func CompareMessageAndBlock(params *BuilderBlockValidationRequestV2, block *type
return nil
}


func (api *BlockValidationAPI) ValidateBuilderSubmissionV2(params *BuilderBlockValidationRequestV2) error {
start := time.Now()
requestId := uuid.New()
Expand Down Expand Up @@ -187,4 +184,3 @@ func (api *BlockValidationAPI) ValidateBuilderSubmissionV2(params *BuilderBlockV
log.Info("validated block", "hash", block.Hash(), "number", block.NumberU64(), "parentHash", block.ParentHash(), "time_elapsed", time.Since(start), "requestId", requestId)
return nil
}

86 changes: 2 additions & 84 deletions eth/block-validation/api_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package blockvalidation

import (
"encoding/json"
"errors"
"math/big"
"os"
Expand All @@ -25,7 +24,6 @@ import (
"github.com/ethereum/go-ethereum/eth"
"github.com/ethereum/go-ethereum/eth/downloader"
"github.com/ethereum/go-ethereum/eth/ethconfig"
"github.com/ethereum/go-ethereum/eth/tracers/logger"
"github.com/ethereum/go-ethereum/miner"
"github.com/ethereum/go-ethereum/node"
"github.com/ethereum/go-ethereum/p2p"
Expand Down Expand Up @@ -59,7 +57,7 @@ func TestValidateBuilderSubmissionV1(t *testing.T) {
ethservice.Merger().ReachTTD()
defer n.Close()

api := NewBlockValidationAPI(ethservice, nil)
api := NewBlockValidationAPI(ethservice)
parent := preMergeBlocks[len(preMergeBlocks)-1]

api.eth.APIBackend.Miner().SetEtherbase(testValidatorAddr)
Expand Down Expand Up @@ -123,25 +121,6 @@ func TestValidateBuilderSubmissionV1(t *testing.T) {
blockRequest.ExecutionPayload.GasLimit -= 1
updatePayloadHash(t, blockRequest)

// TODO: test with contract calling blacklisted address
// Test tx from blacklisted address
api.accessVerifier = &AccessVerifier{
blacklistedAddresses: map[common.Address]struct{}{
testAddr: {},
},
}
require.ErrorContains(t, api.ValidateBuilderSubmissionV1(blockRequest), "transaction from blacklisted address 0x71562b71999873DB5b286dF957af199Ec94617F7")

// Test tx to blacklisted address
api.accessVerifier = &AccessVerifier{
blacklistedAddresses: map[common.Address]struct{}{
{0x16}: {},
},
}
require.ErrorContains(t, api.ValidateBuilderSubmissionV1(blockRequest), "transaction to blacklisted address 0x1600000000000000000000000000000000000000")

api.accessVerifier = nil

blockRequest.Message.GasUsed = 10
require.ErrorContains(t, api.ValidateBuilderSubmissionV1(blockRequest), "incorrect GasUsed 10, expected 119990")
blockRequest.Message.GasUsed = execData.GasUsed
Expand Down Expand Up @@ -173,7 +152,7 @@ func TestValidateBuilderSubmissionV2(t *testing.T) {
ethservice.Merger().ReachTTD()
defer n.Close()

api := NewBlockValidationAPI(ethservice, nil)
api := NewBlockValidationAPI(ethservice)
parent := preMergeBlocks[len(preMergeBlocks)-1]

api.eth.APIBackend.Miner().SetEtherbase(testValidatorAddr)
Expand Down Expand Up @@ -256,25 +235,6 @@ func TestValidateBuilderSubmissionV2(t *testing.T) {
blockRequest.ExecutionPayload.GasLimit -= 1
updatePayloadHashV2(t, blockRequest)

// TODO: test with contract calling blacklisted address
// Test tx from blacklisted address
api.accessVerifier = &AccessVerifier{
blacklistedAddresses: map[common.Address]struct{}{
testAddr: {},
},
}
require.ErrorContains(t, api.ValidateBuilderSubmissionV2(blockRequest), "transaction from blacklisted address 0x71562b71999873DB5b286dF957af199Ec94617F7")

// Test tx to blacklisted address
api.accessVerifier = &AccessVerifier{
blacklistedAddresses: map[common.Address]struct{}{
{0x16}: {},
},
}
require.ErrorContains(t, api.ValidateBuilderSubmissionV2(blockRequest), "transaction to blacklisted address 0x1600000000000000000000000000000000000000")

api.accessVerifier = nil

blockRequest.Message.GasUsed = 10
require.ErrorContains(t, api.ValidateBuilderSubmissionV2(blockRequest), "incorrect GasUsed 10, expected 119996")
blockRequest.Message.GasUsed = execData.GasUsed
Expand Down Expand Up @@ -394,48 +354,6 @@ func assembleBlock(api *BlockValidationAPI, parentHash common.Hash, params *engi
return nil, errors.New("payload did not resolve")
}

func TestBlacklistLoad(t *testing.T) {
file, err := os.CreateTemp(".", "blacklist")
require.NoError(t, err)
defer os.Remove(file.Name())

av, err := NewAccessVerifierFromFile(file.Name())
require.Error(t, err)
require.Nil(t, av)

ba := BlacklistedAddresses{common.Address{0x13}, common.Address{0x14}}
bytes, err := json.MarshalIndent(ba, "", " ")
require.NoError(t, err)
err = os.WriteFile(file.Name(), bytes, 0644)
require.NoError(t, err)

av, err = NewAccessVerifierFromFile(file.Name())
require.NoError(t, err)
require.NotNil(t, av)
require.EqualValues(t, av.blacklistedAddresses, map[common.Address]struct{}{
{0x13}: {},
{0x14}: {},
})

require.NoError(t, av.verifyTraces(logger.NewAccessListTracer(nil, common.Address{}, common.Address{}, nil)))

acl := types.AccessList{
types.AccessTuple{
Address: common.Address{0x14},
},
}
tracer := logger.NewAccessListTracer(acl, common.Address{}, common.Address{}, nil)
require.ErrorContains(t, av.verifyTraces(tracer), "blacklisted address 0x1400000000000000000000000000000000000000 in execution trace")

acl = types.AccessList{
types.AccessTuple{
Address: common.Address{0x15},
},
}
tracer = logger.NewAccessListTracer(acl, common.Address{}, common.Address{}, nil)
require.NoError(t, av.verifyTraces(tracer))
}

func ExecutableDataToExecutionPayload(data *engine.ExecutableData) (*boostTypes.ExecutionPayload, error) {
transactionData := make([]hexutil.Bytes, len(data.Transactions))
for i, tx := range data.Transactions {
Expand Down

0 comments on commit e0d1e28

Please sign in to comment.