Skip to content

Commit

Permalink
Merge branch 'wormhole-foundation-main'
Browse files Browse the repository at this point in the history
  • Loading branch information
joelsmith-2019 committed Sep 6, 2024
2 parents b34da54 + 7002cca commit d5d6d96
Show file tree
Hide file tree
Showing 21 changed files with 790 additions and 6,155 deletions.
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
/solana/ @kcsongor @a5-pickle
/sui/ @kcsongor @a5-pickle @gator-boi
/terra/ @kcsongor @a5-pickle
/wormchain/ @nik-suri
/wormchain/ @nik-suri @johnsaigle @mdulin2 @jtieri

# Utilities

Expand Down
232 changes: 109 additions & 123 deletions node/cmd/guardiand/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,8 @@ var (
xlayerRPC *string
xlayerContract *string

lineaRPC *string
lineaContract *string
lineaRollUpUrl *string
lineaRollUpContract *string
lineaRPC *string
lineaContract *string

berachainRPC *string
berachainContract *string
Expand Down Expand Up @@ -389,8 +387,6 @@ func init() {

lineaRPC = node.RegisterFlagWithValidationOrFail(NodeCmd, "lineaRPC", "Linea RPC URL", "ws://eth-devnet:8545", []string{"ws", "wss"})
lineaContract = NodeCmd.Flags().String("lineaContract", "", "Linea contract address")
lineaRollUpUrl = NodeCmd.Flags().String("lineaRollUpUrl", "", "Linea roll up URL")
lineaRollUpContract = NodeCmd.Flags().String("lineaRollUpContract", "", "Linea roll up contract address")

berachainRPC = node.RegisterFlagWithValidationOrFail(NodeCmd, "berachainRPC", "Berachain RPC URL", "ws://eth-devnet:8545", []string{"ws", "wss"})
berachainContract = NodeCmd.Flags().String("berachainContract", "", "Berachain contract address")
Expand Down Expand Up @@ -619,6 +615,9 @@ func runNode(cmd *cobra.Command, args []string) {

// Verify flags

if *nodeName == "" {
logger.Fatal("Please specify --nodeName")
}
if *nodeKeyPath == "" && env != common.UnsafeDevNet { // In devnet mode, keys are deterministically generated.
logger.Fatal("Please specify --nodeKey")
}
Expand All @@ -643,6 +642,100 @@ func runNode(cmd *cobra.Command, args []string) {
logger.Fatal("Please specify --ethRPC")
}

// In devnet mode, we generate a deterministic guardian key and write it to disk.
if env == common.UnsafeDevNet {
err := devnet.GenerateAndStoreDevnetGuardianKey(*guardianKeyPath)
if err != nil {
logger.Fatal("failed to generate devnet guardian key", zap.Error(err))
}
}

// Load guardian key
gk, err := common.LoadGuardianKey(*guardianKeyPath, env == common.UnsafeDevNet)
if err != nil {
logger.Fatal("failed to load guardian key", zap.Error(err))
}

logger.Info("Loaded guardian key", zap.String(
"address", ethcrypto.PubkeyToAddress(gk.PublicKey).String()))

// Load p2p private key
var p2pKey libp2p_crypto.PrivKey
if env == common.UnsafeDevNet {
idx, err := devnet.GetDevnetIndex()
if err != nil {
logger.Fatal("Failed to parse hostname - are we running in devnet?")
}
p2pKey = devnet.DeterministicP2PPrivKeyByIndex(int64(idx))

if idx != 0 {
firstGuardianName, err := devnet.GetFirstGuardianNameFromBootstrapPeers(*p2pBootstrap)
if err != nil {
logger.Fatal("failed to get first guardian name from bootstrap peers", zap.String("bootstrapPeers", *p2pBootstrap), zap.Error(err))
}
// try to connect to guardian-0
for {
_, err := net.LookupIP(firstGuardianName)
if err == nil {
break
}
logger.Info(fmt.Sprintf("Error resolving %s. Trying again...", firstGuardianName))
time.Sleep(time.Second)
}
// TODO this is a hack. If this is not the bootstrap Guardian, we wait 10s such that the bootstrap Guardian has enough time to start.
// This may no longer be necessary because now the p2p.go ensures that it can connect to at least one bootstrap peer and will
// exit the whole guardian if it is unable to. Sleeping here for a bit may reduce overall startup time by preventing unnecessary restarts, though.
logger.Info("This is not a bootstrap Guardian. Waiting another 10 seconds for the bootstrap guardian to come online.")
time.Sleep(time.Second * 10)
}
} else {
p2pKey, err = common.GetOrCreateNodeKey(logger, *nodeKeyPath)
if err != nil {
logger.Fatal("Failed to load node key", zap.Error(err))
}
}

// Set up telemetry if it is enabled. We can't do this until we have the p2p key and the guardian key.
// Telemetry is enabled by default in mainnet/testnet. In devnet it is disabled by default.
usingLoki := *telemetryLokiURL != ""
if !*disableTelemetry && (env != common.UnsafeDevNet || (env == common.UnsafeDevNet && usingLoki)) {
if !usingLoki {
logger.Fatal("Please specify --telemetryLokiURL or set --disableTelemetry=false")
}

// Get libp2p peer ID from private key
pk := p2pKey.GetPublic()
peerID, err := peer.IDFromPublicKey(pk)
if err != nil {
logger.Fatal("Failed to get peer ID from private key", zap.Error(err))
}

labels := map[string]string{
"node_name": *nodeName,
"node_key": peerID.String(),
"guardian_addr": ethcrypto.PubkeyToAddress(gk.PublicKey).String(),
"network": *p2pNetworkID,
"version": version.Version(),
}

skipPrivateLogs := !*publicRpcLogToTelemetry

var tm *telemetry.Telemetry
if usingLoki {
logger.Info("Using Loki telemetry logger",
zap.String("publicRpcLogDetail", *publicRpcLogDetailStr),
zap.Bool("logPublicRpcToTelemetry", *publicRpcLogToTelemetry))

tm, err = telemetry.NewLokiCloudLogger(context.Background(), logger, *telemetryLokiURL, "wormhole", skipPrivateLogs, labels)
if err != nil {
logger.Fatal("Failed to initialize telemetry", zap.Error(err))
}
}

defer tm.Close()
logger = tm.WrapLogger(logger) // Wrap logger with telemetry logger
}

// Validate the args for all the EVM chains. The last flag indicates if the chain is allowed in mainnet.
*ethContract = checkEvmArgs(logger, *ethRPC, *ethContract, "eth", true)
*bscContract = checkEvmArgs(logger, *bscRPC, *bscContract, "bsc", true)
Expand All @@ -662,6 +755,7 @@ func runNode(cmd *cobra.Command, args []string) {
*mantleContract = checkEvmArgs(logger, *mantleRPC, *mantleContract, "mantle", true)
*blastContract = checkEvmArgs(logger, *blastRPC, *blastContract, "blast", true)
*xlayerContract = checkEvmArgs(logger, *xlayerRPC, *xlayerContract, "xlayer", true)
*lineaContract = checkEvmArgs(logger, *lineaRPC, *lineaContract, "linea", true)
*berachainContract = checkEvmArgs(logger, *berachainRPC, *berachainContract, "berachain", false)
*snaxchainContract = checkEvmArgs(logger, *snaxchainRPC, *snaxchainContract, "snaxchain", true)

Expand All @@ -673,12 +767,6 @@ func runNode(cmd *cobra.Command, args []string) {
*holeskyContract = checkEvmArgs(logger, *holeskyRPC, *holeskyContract, "holesky", false)
*polygonSepoliaContract = checkEvmArgs(logger, *polygonSepoliaRPC, *polygonSepoliaContract, "polygonSepolia", false)

// Linea requires a couple of additional parameters.
*lineaContract = checkEvmArgs(logger, *lineaRPC, *lineaContract, "linea", false)
if (*lineaRPC != "") && (*lineaRollUpUrl == "" || *lineaRollUpContract == "") && env != common.UnsafeDevNet {
logger.Fatal("If --lineaRPC is specified, --lineaRollUpUrl and --lineaRollUpContract must also be specified")
}

if !argsConsistent([]string{*solanaContract, *solanaRPC}) {
logger.Fatal("Both --solanaContract and --solanaRPC must be set or both unset")
}
Expand Down Expand Up @@ -743,10 +831,6 @@ func runNode(cmd *cobra.Command, args []string) {
logger.Fatal("--publicRpcLogDetail should be one of (none, minimal, full)")
}

if *nodeName == "" {
logger.Fatal("Please specify --nodeName")
}

// Complain about Infura on mainnet.
//
// As it turns out, Infura has a bug where it would sometimes incorrectly round
Expand All @@ -770,63 +854,6 @@ func runNode(cmd *cobra.Command, args []string) {
logger.Fatal("Infura is known to send incorrect blocks - please use your own nodes")
}

// In devnet mode, we generate a deterministic guardian key and write it to disk.
if env == common.UnsafeDevNet {
err := devnet.GenerateAndStoreDevnetGuardianKey(*guardianKeyPath)
if err != nil {
logger.Fatal("failed to generate devnet guardian key", zap.Error(err))
}
}

// Database
db := db.OpenDb(logger, dataDir)
defer db.Close()

// Guardian key
gk, err := common.LoadGuardianKey(*guardianKeyPath, env == common.UnsafeDevNet)
if err != nil {
logger.Fatal("failed to load guardian key", zap.Error(err))
}

logger.Info("Loaded guardian key", zap.String(
"address", ethcrypto.PubkeyToAddress(gk.PublicKey).String()))

// Load p2p private key
var p2pKey libp2p_crypto.PrivKey
if env == common.UnsafeDevNet {
idx, err := devnet.GetDevnetIndex()
if err != nil {
logger.Fatal("Failed to parse hostname - are we running in devnet?")
}
p2pKey = devnet.DeterministicP2PPrivKeyByIndex(int64(idx))

if idx != 0 {
firstGuardianName, err := devnet.GetFirstGuardianNameFromBootstrapPeers(*p2pBootstrap)
if err != nil {
logger.Fatal("failed to get first guardian name from bootstrap peers", zap.String("bootstrapPeers", *p2pBootstrap), zap.Error(err))
}
// try to connect to guardian-0
for {
_, err := net.LookupIP(firstGuardianName)
if err == nil {
break
}
logger.Info(fmt.Sprintf("Error resolving %s. Trying again...", firstGuardianName))
time.Sleep(time.Second)
}
// TODO this is a hack. If this is not the bootstrap Guardian, we wait 10s such that the bootstrap Guardian has enough time to start.
// This may no longer be necessary because now the p2p.go ensures that it can connect to at least one bootstrap peer and will
// exit the whole guardian if it is unable to. Sleeping here for a bit may reduce overall startup time by preventing unnecessary restarts, though.
logger.Info("This is not a bootstrap Guardian. Waiting another 10 seconds for the bootstrap guardian to come online.")
time.Sleep(time.Second * 10)
}
} else {
p2pKey, err = common.GetOrCreateNodeKey(logger, *nodeKeyPath)
if err != nil {
logger.Fatal("Failed to load node key", zap.Error(err))
}
}

rpcMap := make(map[string]string)
rpcMap["acalaRPC"] = *acalaRPC
rpcMap["accountantWS"] = *accountantWS
Expand Down Expand Up @@ -898,55 +925,16 @@ func runNode(cmd *cobra.Command, args []string) {
rootCtxCancel()
}()

usingLoki := *telemetryLokiURL != ""

var hasTelemetryCredential bool = usingLoki

// Telemetry is enabled by default in mainnet/testnet. In devnet it is disabled by default
if !*disableTelemetry && (env != common.UnsafeDevNet || (env == common.UnsafeDevNet && hasTelemetryCredential)) {
if !hasTelemetryCredential {
logger.Fatal("Please specify --telemetryLokiURL or set --disableTelemetry=false")
}

// Get libp2p peer ID from private key
pk := p2pKey.GetPublic()
peerID, err := peer.IDFromPublicKey(pk)
if err != nil {
logger.Fatal("Failed to get peer ID from private key", zap.Error(err))
}

labels := map[string]string{
"node_name": *nodeName,
"node_key": peerID.String(),
"guardian_addr": ethcrypto.PubkeyToAddress(gk.PublicKey).String(),
"network": *p2pNetworkID,
"version": version.Version(),
}

skipPrivateLogs := !*publicRpcLogToTelemetry

var tm *telemetry.Telemetry
if usingLoki {
logger.Info("Using Loki telemetry logger",
zap.String("publicRpcLogDetail", *publicRpcLogDetailStr),
zap.Bool("logPublicRpcToTelemetry", *publicRpcLogToTelemetry))

tm, err = telemetry.NewLokiCloudLogger(context.Background(), logger, *telemetryLokiURL, "wormhole", skipPrivateLogs, labels)
if err != nil {
logger.Fatal("Failed to initialize telemetry", zap.Error(err))
}
}

defer tm.Close()
logger = tm.WrapLogger(logger) // Wrap logger with telemetry logger
}

// log golang version
logger.Info("golang version", zap.String("golang_version", runtime.Version()))

// Redirect ipfs logs to plain zap
ipfslog.SetPrimaryCore(logger.Core())

// Database
db := db.OpenDb(logger.With(zap.String("component", "badgerDb")), dataDir)
defer db.Close()

wormchainId := "wormchain"
if env == common.TestNet {
wormchainId = "wormchain-testnet-0"
Expand Down Expand Up @@ -1312,13 +1300,11 @@ func runNode(cmd *cobra.Command, args []string) {

if shouldStart(lineaRPC) {
wc := &evm.WatcherConfig{
NetworkID: "linea",
ChainID: vaa.ChainIDLinea,
Rpc: *lineaRPC,
Contract: *lineaContract,
CcqBackfillCache: *ccqBackfillCache,
LineaRollUpUrl: *lineaRollUpUrl,
LineaRollUpContract: *lineaRollUpContract,
NetworkID: "linea",
ChainID: vaa.ChainIDLinea,
Rpc: *lineaRPC,
Contract: *lineaContract,
CcqBackfillCache: *ccqBackfillCache,
}

watcherConfigs = append(watcherConfigs, wc)
Expand Down
18 changes: 12 additions & 6 deletions node/hack/repair_solana/repair.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func main() {
offset := firstSeq - p.Sequence - 10
log.Printf("repairing: %d (offset %d)", p.Sequence, offset)

var tx *rpc.TransactionWithMeta
var tx *rpc.GetTransactionResult
var nseq uint64
var err error

Expand Down Expand Up @@ -243,8 +243,14 @@ func main() {
}
}

func fetchTxSeq(ctx context.Context, c *rpc.Client, sig solana.Signature) (*rpc.TransactionWithMeta, uint64, error) {
out, err := c.GetConfirmedTransaction(ctx, sig)
func fetchTxSeq(ctx context.Context, c *rpc.Client, sig solana.Signature) (*rpc.GetTransactionResult, uint64, error) {
maxSupportedTransactionVersion := uint64(0)
params := rpc.GetTransactionOpts{
Encoding: solana.EncodingBase64,
Commitment: rpc.CommitmentConfirmed,
MaxSupportedTransactionVersion: &maxSupportedTransactionVersion,
}
out, err := c.GetTransaction(ctx, sig, &params)
if err != nil {
return nil, 0, fmt.Errorf("GetConfirmedTransaction: %v", err)
}
Expand All @@ -262,14 +268,14 @@ func fetchTxSeq(ctx context.Context, c *rpc.Client, sig solana.Signature) (*rpc.
return nil, 0, nil
}

func process(txRpc *rpc.TransactionWithMeta) (*solana.PublicKey, error) {
func process(out *rpc.GetTransactionResult) (*solana.PublicKey, error) {
program, err := solana.PublicKeyFromBase58(*solanaAddr)
if err != nil {
log.Fatalf("Invalid program address: %v", err)
return nil, err
}

tx, err := txRpc.GetTransaction()
tx, err := out.Transaction.GetTransaction()
if err != nil {
log.Fatalf("Failed to unmarshal transaction: %v", err)
return nil, err
Expand All @@ -290,7 +296,7 @@ func process(txRpc *rpc.TransactionWithMeta) (*solana.PublicKey, error) {

txs := make([]solana.CompiledInstruction, 0, len(tx.Message.Instructions))
txs = append(txs, tx.Message.Instructions...)
for _, inner := range txRpc.Meta.InnerInstructions {
for _, inner := range out.Meta.InnerInstructions {
txs = append(txs, inner.Instructions...)
}

Expand Down
Loading

0 comments on commit d5d6d96

Please sign in to comment.