Skip to content

Commit

Permalink
clean up netconf
Browse files Browse the repository at this point in the history
  • Loading branch information
edisonz0718 committed Aug 22, 2024
1 parent 394b608 commit 4c22a43
Show file tree
Hide file tree
Showing 14 changed files with 11 additions and 925 deletions.
15 changes: 0 additions & 15 deletions client/Dockerfile

This file was deleted.

2 changes: 1 addition & 1 deletion client/app/rollback.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
)

func Rollback(ctx context.Context, cfg Config, removeBlock bool) error {
engineCl, err := newEngineClient(ctx, cfg, cfg.Network, nil)
engineCl, err := newEngineClient(ctx, cfg)
if err != nil {
return err
}
Expand Down
10 changes: 2 additions & 8 deletions client/app/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
storetypes "cosmossdk.io/store/types"

cmtcfg "github.com/cometbft/cometbft/config"
"github.com/cometbft/cometbft/crypto"
"github.com/cometbft/cometbft/node"
"github.com/cometbft/cometbft/p2p"
"github.com/cometbft/cometbft/proxy"
Expand All @@ -31,7 +30,6 @@ import (
"github.com/piplabs/story/lib/ethclient"
"github.com/piplabs/story/lib/k1util"
"github.com/piplabs/story/lib/log"
"github.com/piplabs/story/lib/netconf"
"github.com/piplabs/story/lib/tracer"
)

Expand Down Expand Up @@ -108,7 +106,7 @@ func Start(ctx context.Context, cfg Config) (func(context.Context) error, error)
return nil, errors.Wrap(err, "make base app opts")
}

engineCl, err := newEngineClient(ctx, cfg, cfg.Network, privVal.Key.PubKey)
engineCl, err := newEngineClient(ctx, cfg)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -277,11 +275,7 @@ func chainIDFromGenesis(cfg Config) (string, error) {
}

// newEngineClient returns a new engine API client.
func newEngineClient(ctx context.Context, cfg Config, network netconf.ID, pubkey crypto.PubKey) (ethclient.EngineClient, error) {
if network == netconf.Simnet {
return ethclient.NewEngineMock(ethclient.WithMockSelfDelegation(pubkey, 1))
}

func newEngineClient(ctx context.Context, cfg Config) (ethclient.EngineClient, error) {
jwtBytes, err := ethclient.LoadJWTHexFile(cfg.EngineJWTFile)
if err != nil {
return nil, errors.Wrap(err, "load engine JWT file")
Expand Down
74 changes: 0 additions & 74 deletions client/cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,17 @@ import (
"os"
"path/filepath"
"strings"
"time"

cmtconfig "github.com/cometbft/cometbft/config"
k1 "github.com/cometbft/cometbft/crypto/secp256k1"
cmtos "github.com/cometbft/cometbft/libs/os"
"github.com/cometbft/cometbft/p2p"
"github.com/cometbft/cometbft/privval"
rpchttp "github.com/cometbft/cometbft/rpc/client/http"
"github.com/cometbft/cometbft/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/ethereum/go-ethereum/common"
"github.com/spf13/cobra"

iliadcfg "github.com/piplabs/story/client/config"
"github.com/piplabs/story/client/genutil"
libcmd "github.com/piplabs/story/lib/cmd"
"github.com/piplabs/story/lib/errors"
"github.com/piplabs/story/lib/log"
Expand Down Expand Up @@ -142,25 +138,6 @@ func InitFiles(ctx context.Context, initCfg InitConfig) error {
comet.P2P.Seeds = strings.Join(seeds, ",")
}

if initCfg.TrustedSync && network.IsProtected() {
rpcServer := fmt.Sprintf("https://rpc.consensus.%s.storyprotocol", network)

// Trusted state sync only supported for protected networks.
height, hash, err := getTrustHeightAndHash(ctx, rpcServer)
if err != nil {
return errors.Wrap(err, "get trusted height")
}

comet.StateSync.Enable = true
comet.StateSync.RPCServers = []string{rpcServer, rpcServer} // CometBFT requires two RPC servers. Duplicate our RPC for now.
comet.StateSync.TrustHeight = height
comet.StateSync.TrustHash = hash

log.Info(ctx, "Trusted state-sync enabled", "height", height, "hash", hash, "rpc_endpoint", rpcServer)
} else {
log.Info(ctx, "Not initializing trusted state sync")
}

// Setup comet config
cmtConfigFile := filepath.Join(homeDir, cmtconfig.DefaultConfigDir, cmtconfig.DefaultConfigFileName)
if cmtos.FileExists(cmtConfigFile) {
Expand Down Expand Up @@ -212,34 +189,6 @@ func InitFiles(ctx context.Context, initCfg InitConfig) error {
genFile := comet.GenesisFile()
if cmtos.FileExists(genFile) {
log.Info(ctx, "Found genesis file", "path", genFile)
} else if network == netconf.Simnet {
pubKey, err := pv.GetPubKey()
if err != nil {
return errors.Wrap(err, "get public key")
}

var genDoc *types.GenesisDoc
if initCfg.Cosmos {
cosmosGen, err := genutil.MakeGenesis(network, time.Now(), initCfg.ExecutionHash, pubKey)
if err != nil {
return err
}

genDoc, err = cosmosGen.ToGenesisDoc()
if err != nil {
return errors.Wrap(err, "convert to genesis doc")
}
} else {
genDoc, err = MakeGenesis(network, pubKey)
if err != nil {
return err
}
}

if err := genDoc.SaveAs(genFile); err != nil {
return errors.Wrap(err, "save genesis file")
}
log.Info(ctx, "Generated simnet genesis file", "path", genFile)
} else if len(network.Static().ConsensusGenesisJSON) > 0 {
if err := os.WriteFile(genFile, network.Static().ConsensusGenesisJSON, 0o644); err != nil {
return errors.Wrap(err, "failed to write genesis file")
Expand Down Expand Up @@ -273,29 +222,6 @@ func InitFiles(ctx context.Context, initCfg InitConfig) error {
return nil
}

func getTrustHeightAndHash(ctx context.Context, baseURL string) (int64, string, error) {
cl, err := rpchttp.New(baseURL, "/websocket")
if err != nil {
return 0, "", errors.Wrap(err, "create rpc client")
}

latest, err := cl.Block(ctx, nil)
if err != nil {
return 0, "", errors.Wrap(err, "get latest block")
}

// Truncate height to last defaultSnapshotPeriod
const defaultSnapshotPeriod int64 = 1000
snapshotHeight := defaultSnapshotPeriod * (latest.Block.Height / defaultSnapshotPeriod)

b, err := cl.Block(ctx, &snapshotHeight)
if err != nil {
return 0, "", errors.Wrap(err, "get snapshot block")
}

return b.Block.Height, b.BlockID.Hash.String(), nil
}

func checkHomeDir(homeDir string) error {
files, _ := os.ReadDir(homeDir) // Ignore error, we'll just assume it's empty.
for _, file := range files {
Expand Down
4 changes: 2 additions & 2 deletions client/cmd/init_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func TestInitFiles(t *testing.T) {
dir := t.TempDir()
cfg := InitConfig{
HomeDir: dir,
Network: netconf.Simnet,
Network: netconf.Local,
}
err := InitFiles(context.Background(), cfg)
require.NoError(t, err)
Expand All @@ -46,7 +46,7 @@ func TestInitForce(t *testing.T) {

cfg := InitConfig{
HomeDir: dir,
Network: netconf.Simnet,
Network: netconf.Local,
}

err = InitFiles(context.Background(), cfg)
Expand Down
120 changes: 0 additions & 120 deletions client/genutil/evm/evm.go

This file was deleted.

Loading

0 comments on commit 4c22a43

Please sign in to comment.