Skip to content

Commit

Permalink
fxed bug payload builder flags
Browse files Browse the repository at this point in the history
  • Loading branch information
rezbera committed Jan 30, 2025
1 parent 2cca165 commit 751fc88
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 17 deletions.
19 changes: 15 additions & 4 deletions cli/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ const (
BeaconKitAcceptTos = beaconKitRoot + "accept-tos"

// Builder Config.
builderRoot = beaconKitRoot + "payload-builder."
SuggestedFeeRecipient = builderRoot + "suggested-fee-recipient"
LocalBuilderEnabled = builderRoot + "local-builder-enabled"
LocalBuildPayloadTimeout = builderRoot + "local-build-payload-timeout"
builderRoot = beaconKitRoot + "payload-builder."
SuggestedFeeRecipient = builderRoot + "suggested-fee-recipient"
BuilderEnabled = builderRoot + "enabled"
BuildPayloadTimeout = builderRoot + "payload-timeout"

// Validator Config.
validatorRoot = beaconKitRoot + "validator."
Expand Down Expand Up @@ -105,6 +105,17 @@ func AddBeaconKitFlags(startCmd *cobra.Command) {
defaultCfg.Engine.RPCJWTRefreshInterval,
"rpc jwt refresh interval",
)
startCmd.Flags().Bool(
BuilderEnabled,
defaultCfg.PayloadBuilder.Enabled,
"payload builder is enabled",
)

startCmd.Flags().Duration(
BuildPayloadTimeout,
defaultCfg.PayloadBuilder.PayloadTimeout,
"payload builder timeout",
)
startCmd.Flags().String(
SuggestedFeeRecipient,
defaultCfg.PayloadBuilder.SuggestedFeeRecipient.Hex(),
Expand Down
4 changes: 4 additions & 0 deletions testing/injected-consensus/config/addrbook.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"key": "385d575392b37155f228070d",
"addrs": []
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"key": "385d575392b37155f228070d",
"addrs": []
}
25 changes: 25 additions & 0 deletions testing/injected-consensus/injected-consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
package injectedconsensus

import (
"context"
"crypto/rand"
"encoding/hex"
"fmt"
Expand All @@ -40,6 +41,8 @@ import (
nodebuilder "github.com/berachain/beacon-kit/node-core/builder"
"github.com/berachain/beacon-kit/node-core/components"
nodetypes "github.com/berachain/beacon-kit/node-core/types"
payloadbuilder "github.com/berachain/beacon-kit/payload/builder"
"github.com/berachain/beacon-kit/primitives/common"
"github.com/berachain/beacon-kit/storage/db"
cmtcfg "github.com/cometbft/cometbft/config"
dbm "github.com/cosmos/cosmos-db"
Expand Down Expand Up @@ -106,6 +109,8 @@ type TestNode struct {
BlockchainService *blockchain.Service
CometConfig *cmtcfg.Config
Homedir string
Context context.Context
CancelFunc context.CancelFunc
}

func makeTempHomeDir(t *testing.T) string {

Check failure on line 116 in testing/injected-consensus/injected-consensus.go

View workflow job for this annotation

GitHub Actions / lint

func `makeTempHomeDir` is unused (unused)
Expand Down Expand Up @@ -152,6 +157,9 @@ func copyFile(t *testing.T, src, dst string) error {
// NewTestNode starts a node with a custom consensus driver so we can manually drive the ABCI calls.
func NewTestNode(t *testing.T) *TestNode {
t.Helper()

// Create a test node that
ctx, cancelFunc := context.WithCancel(context.Background())
// 1. Build a node builder with your default or custom test components.
nb := nodebuilder.New(
nodebuilder.WithComponents[
Expand All @@ -169,28 +177,43 @@ func NewTestNode(t *testing.T) *TestNode {
// Use an in-memory DB
// db := dbm.NewMemDB()
cmtCfg := cometbft.DefaultConfig()
cmtCfg.RootDir = tempHomeDir

beaconCfg := config.DefaultConfig()
executionClientConfig := executionconfig.DefaultConfig()

payloadBuilderCfg := payloadbuilder.DefaultConfig()

appOpts := viper.New()

// err := copyFile(t, "./test_priv_validator_key.json", tempHomeDir+"/priv_validator_key.json")
// require.NoError(t, err)
// err = copyFile(t, "./test_priv_validator_state.json", tempHomeDir+"/priv_validator_state.json")
// require.NoError(t, err)

// Execution Client Config
appOpts.Set(flags.JWTSecretPath, "../files/jwt.hex")
appOpts.Set(flags.RPCJWTRefreshInterval, executionClientConfig.RPCJWTRefreshInterval)
appOpts.Set(flags.RPCStartupCheckInterval, executionClientConfig.RPCStartupCheckInterval)
appOpts.Set(flags.RPCDialURL, executionClientConfig.RPCDialURL)

// BLS Config
appOpts.Set(flags.PrivValidatorKeyFile, "./config/priv_validator_key.json")
appOpts.Set(flags.PrivValidatorStateFile, "./data/priv_validator_state.json")

// Beacon Config
appOpts.Set(flags.BlockStoreServiceAvailabilityWindow, beaconCfg.BlockStoreService.AvailabilityWindow)
appOpts.Set(flags.BlockStoreServiceEnabled, beaconCfg.BlockStoreService.Enabled)
appOpts.Set(flags.KZGTrustedSetupPath, "../files/kzg-trusted-setup.json")
appOpts.Set(flags.KZGImplementation, kzg.DefaultConfig().Implementation)

// Payload Builder Config
payloadBuilderCfg.SuggestedFeeRecipient = common.NewExecutionAddressFromHex("0x981114102592310C347E61368342DDA67017bf84")
appOpts.Set(flags.BuilderEnabled, payloadBuilderCfg.Enabled)
appOpts.Set(flags.BuildPayloadTimeout, payloadBuilderCfg.PayloadTimeout)
appOpts.Set(flags.SuggestedFeeRecipient, payloadBuilderCfg.SuggestedFeeRecipient)

// Chain Spec
t.Setenv(components.ChainSpecTypeEnvVar, components.DevnetChainSpecType)

// TODO: Cleanup this Set
Expand Down Expand Up @@ -224,6 +247,8 @@ func NewTestNode(t *testing.T) *TestNode {
BlockchainService: blockchainService,
CometConfig: cmtCfg,
Homedir: tempHomeDir,
Context: ctx,
CancelFunc: cancelFunc,
}
}

Expand Down
23 changes: 10 additions & 13 deletions testing/injected-consensus/invalid_block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
package injectedconsensus_test

import (
"context"
"os"
"testing"
"time"

Expand All @@ -42,29 +40,28 @@ func (s *InjectedConsensus) SetupTest() {

func (s *InjectedConsensus) TearDownTest() {
// Ensure teardown runs no matter what
err := os.RemoveAll(s.testNode.Homedir)
s.Require().NoError(err)
s.testNode.CancelFunc()
// err := os.RemoveAll(s.testNode.Homedir)
// s.Require().NoError(err)
}

func (s *InjectedConsensus) TestInitChainRequestsInvalidChainID() {
// Create a test node that
ctx, cancelFunc := context.WithCancel(context.Background())
defer cancelFunc()

request := &comettypes.InitChainRequest{
ChainId: "80090",
}
_, err := s.testNode.CometService.InitChain(ctx, request)
_, err := s.testNode.CometService.InitChain(s.testNode.Context, request)
s.Require().Error(err, "invalid chain-id on InitChain; expected: beacond-2061, got: 80090")
}

// TestProcessProposalRequestInvalidBlock tests the scenario where a peer sends us a block with an invalid timestamp.
func (s *InjectedConsensus) TestProcessProposalRequestInvalidBlock() {
// Create a test node that
_, cancelFunc := context.WithCancel(context.Background())
defer cancelFunc()
go func() {

Check failure on line 58 in testing/injected-consensus/invalid_block_test.go

View workflow job for this annotation

GitHub Actions / lint

SA2002: the goroutine calls T.Fatal, which must be called in the same goroutine as the test (staticcheck)
if err := s.testNode.Node.Start(s.testNode.Context); err != nil {
s.T().Fatal(err)

Check failure on line 60 in testing/injected-consensus/invalid_block_test.go

View workflow job for this annotation

GitHub Actions / lint

SA2002(related information): call to T.Fatal (staticcheck)
}
}()

<-time.After(20 * time.Second)
<-time.After(120 * time.Second)

// genesis := genesisFromFile(t, testNode.cometConfig.Genesis)

Expand Down

0 comments on commit 751fc88

Please sign in to comment.