Terra key moved out from env variable, VAA submission on Terra made async (#129)

* Terra fee payer key moved from environment variable into the separate file

* Removed closed issues from the comments, VAA submition made async

* Review comments fixed
This commit is contained in:
Yuriy Savchenko 2020-11-30 20:24:39 +02:00 committed by GitHub
parent 106fecca00
commit cc412605c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 48 additions and 22 deletions

View File

@ -52,7 +52,7 @@ var (
terraLCD *string
terraChaidID *string
terraContract *string
terraFeePayer *string
terraKeyPath *string
agentRPC *string
@ -83,7 +83,7 @@ func init() {
terraLCD = BridgeCmd.Flags().String("terraLCD", "", "Path to LCD service root for http calls")
terraChaidID = BridgeCmd.Flags().String("terraChainID", "", "Terra chain ID, used in LCD client initialization")
terraContract = BridgeCmd.Flags().String("terraContract", "", "Wormhole contract address on Terra blockhain")
terraFeePayer = BridgeCmd.Flags().String("terraFeePayer", "", "Mnemonic to account paying gas for submitting transactions to Terra")
terraKeyPath = BridgeCmd.Flags().String("terraKey", "", "Path to mnemonic for account paying gas for submitting transactions to Terra")
agentRPC = BridgeCmd.Flags().String("agentRPC", "", "Solana agent sidecar gRPC socket path")
@ -250,8 +250,8 @@ func runBridge(cmd *cobra.Command, args []string) {
if *terraContract == "" {
logger.Fatal("Please specify --terraContract")
}
if *terraFeePayer == "" {
logger.Fatal("Please specify --terraFeePayer")
if *terraKeyPath == "" {
logger.Fatal("Please specify --terraKey")
}
}
@ -316,6 +316,18 @@ func runBridge(cmd *cobra.Command, args []string) {
}
}
// Load Terra fee payer key
var terraFeePayer string
if *terraSupport {
if *unsafeDevMode {
terra.WriteDevnetKey(*terraKeyPath)
}
terraFeePayer, err = terra.ReadKey(*terraKeyPath)
if err != nil {
logger.Fatal("Failed to load Terra fee payer key", zap.Error(err))
}
}
adminService, err := adminServiceRunnable(logger, *adminSocketPath, injectC)
if err != nil {
logger.Fatal("failed to create admin service socket", zap.Error(err))
@ -363,7 +375,7 @@ func runBridge(cmd *cobra.Command, args []string) {
*terraLCD,
*terraChaidID,
*terraContract,
*terraFeePayer,
terraFeePayer,
)
if err := supervisor.Run(ctx, "processor", p.Run); err != nil {
return err

View File

@ -57,6 +57,9 @@ const (
// ERC20 default precision.
ERC20DefaultPrecision = 1e18
// Terra devnet fee payer mnemonic
TerraFeePayerKey = "notice oak worry limit wrap speak medal online prefer cluster roof addict wrist behave treat actual wasp year salad speed social layer crew genius"
)
func DeriveAccount(accountIndex uint) accounts.Account {

View File

@ -160,7 +160,7 @@ func (p *Processor) handleObservation(ctx context.Context, m *gossipv1.SignedObs
// be expected to pay the fees. We only submit to Ethereum in devnet mode.
p.devnetVAASubmission(ctx, signed, hash)
case vaa.ChainIDTerra:
p.terraVAASubmission(ctx, signed, hash)
go p.terraVAASubmission(ctx, signed, hash)
default:
p.logger.Error("unknown target chain ID",
zap.String("digest", hash),
@ -211,12 +211,6 @@ func (p *Processor) devnetVAASubmission(ctx context.Context, signed *vaa.VAA, ha
// Submit VAA to Terra.
func (p *Processor) terraVAASubmission(ctx context.Context, signed *vaa.VAA, hash string) {
// Terra support is not yet ready for production.
// - https://github.com/certusone/wormhole/issues/83
// - https://github.com/certusone/wormhole/issues/95
// - https://github.com/certusone/wormhole/issues/97
//
// Roadmap: https://github.com/certusone/wormhole/milestone/4
if !p.devnetMode || !p.terraEnabled {
p.logger.Warn("ignoring terra VAA submission",
zap.String("digest", hash))

View File

@ -3,8 +3,11 @@ package terra
import (
"context"
"encoding/json"
"io/ioutil"
"time"
"github.com/certusone/wormhole/bridge/pkg/devnet"
"github.com/certusone/wormhole/bridge/pkg/vaa"
"github.com/terra-project/terra.go/client"
"github.com/terra-project/terra.go/key"
@ -12,11 +15,11 @@ import (
"github.com/terra-project/terra.go/tx"
)
type SubmitVAAMsg struct {
Params SubmitVAAParams `json:"submit_v_a_a"`
type submitVAAMsg struct {
Params submitVAAParams `json:"submit_v_a_a"`
}
type SubmitVAAParams struct {
type submitVAAParams struct {
VAA []byte `json:"vaa"`
}
@ -58,8 +61,8 @@ func SubmitVAA(ctx context.Context, urlLCD string, chainID string, contractAddre
}
// Create tx
contractCall, err := json.Marshal(SubmitVAAMsg{
Params: SubmitVAAParams{
contractCall, err := json.Marshal(submitVAAMsg{
Params: submitVAAParams{
VAA: vaaBytes,
}})
@ -85,3 +88,20 @@ func SubmitVAA(ctx context.Context, urlLCD string, chainID string, contractAddre
// Broadcast
return LCDClient.Broadcast(ctx, transaction)
}
// ReadKey reads file and returns its content as a string
func ReadKey(path string) (string, error) {
b, err := ioutil.ReadFile(path)
if err != nil {
return "", err
}
return string(b), nil
}
// WriteDevnetKey writes default devnet key to the file
func WriteDevnetKey(path string) {
err := ioutil.WriteFile(path, []byte(devnet.TerraFeePayerKey), 0600)
if err != nil {
panic("Cannot write Terra key file")
}
}

View File

@ -41,9 +41,6 @@ spec:
containers:
- name: guardiand
image: guardiand-image
env:
- name: TERRA_FEE_PAYER
value: "notice oak worry limit wrap speak medal online prefer cluster roof addict wrist behave treat actual wasp year salad speed social layer crew genius"
volumeMounts:
- mountPath: /run/bridge
name: bridge-rundir
@ -72,8 +69,8 @@ spec:
# - localterra
# - --terraContract
# - terra174kgn5rtw4kf6f938wm7kwh70h2v4vcfd26jlc
# - --terraFeePayer
# - $(TERRA_FEE_PAYER)
# - --terraKey
# - /tmp/terra.key
- --agentRPC
- /run/bridge/agent.sock
- --ethConfirmations