bridge: allow specifying skip_preflight in debug VAA submission

This allows forcibly submitting a failing VAA on-chain in cases where
the preflight check would hinder debugging.

It does not change behavior of guardiand.

Co-authored-by: Hendrik Hofstadt <hendrik@nexantic.com>
Change-Id: I63df22049ad27f659dc0638190edd20628b7a338
This commit is contained in:
Leo 2021-03-19 16:58:01 +01:00 committed by Leopold Schabel
parent c1c2c7ae49
commit 79cc6a9f46
5 changed files with 16 additions and 11 deletions

View File

@ -13,11 +13,13 @@ import (
)
var (
agentRPC *string
agentRPC *string
skipPreflight *bool
)
func init() {
agentRPC = postVaaSolanaCmd.Flags().String("agentRPC", "", "Solana agent sidecar gRPC socket path")
skipPreflight = postVaaSolanaCmd.Flags().Bool("skipPreflight", false, "Set skip_preflight flag on submission")
DebugCmd.AddCommand(postVaaSolanaCmd)
}
@ -32,7 +34,7 @@ var postVaaSolanaCmd = &cobra.Command{
}
supervisor.New(context.Background(), logger, func(ctx context.Context) error {
if err := supervisor.Run(ctx, "solvaa",
solana.NewSolanaVAASubmitter(*agentRPC, vaaQueue).Run); err != nil {
solana.NewSolanaVAASubmitter(*agentRPC, vaaQueue, *skipPreflight).Run); err != nil {
return err
}

View File

@ -410,7 +410,7 @@ func runBridge(cmd *cobra.Command, args []string) {
}
if err := supervisor.Run(ctx, "solvaa",
solana.NewSolanaVAASubmitter(*agentRPC, solanaVaaC).Run); err != nil {
solana.NewSolanaVAASubmitter(*agentRPC, solanaVaaC, false).Run); err != nil {
return err
}

View File

@ -42,13 +42,14 @@ func init() {
type (
SolanaVAASubmitter struct {
url string
vaaChan chan *vaa.VAA
url string
vaaChan chan *vaa.VAA
skipPreflight bool
}
)
func NewSolanaVAASubmitter(url string, vaaQueue chan *vaa.VAA) *SolanaVAASubmitter {
return &SolanaVAASubmitter{url: url, vaaChan: vaaQueue}
func NewSolanaVAASubmitter(url string, vaaQueue chan *vaa.VAA, skipPreflight bool) *SolanaVAASubmitter {
return &SolanaVAASubmitter{url: url, vaaChan: vaaQueue, skipPreflight: skipPreflight}
}
func (e *SolanaVAASubmitter) Run(ctx context.Context) error {
@ -112,7 +113,7 @@ func (e *SolanaVAASubmitter) Run(ctx context.Context) error {
h := hex.EncodeToString(m.Bytes())
timeout, cancel := context.WithTimeout(ctx, 120*time.Second)
res, err := c.SubmitVAA(timeout, &agentv1.SubmitVAARequest{Vaa: vaaBytes})
res, err := c.SubmitVAA(timeout, &agentv1.SubmitVAARequest{Vaa: vaaBytes, SkipPreflight: e.skipPreflight})
cancel()
if err != nil {
st, ok := status.FromError(err)

View File

@ -16,6 +16,7 @@ message Empty {
message SubmitVAARequest {
bytes vaa = 1;
bool skip_preflight = 2;
}
message SubmitVAAResponse {

View File

@ -92,7 +92,7 @@ impl Agent for AgentImpl {
};
for mut tx in verify_txs {
match sign_and_send(&rpc, &mut tx, vec![&key]) {
match sign_and_send(&rpc, &mut tx, vec![&key], request.skip_preflight) {
Ok(_) => (),
Err(e) => {
return Err(Status::new(
@ -104,7 +104,7 @@ impl Agent for AgentImpl {
}
let mut transaction2 = Transaction::new_with_payer(&[ix], Some(&key.pubkey()));
match sign_and_send(&rpc, &mut transaction2, vec![&key]) {
match sign_and_send(&rpc, &mut transaction2, vec![&key], request.skip_preflight) {
Ok(s) => Ok(Response::new(SubmitVaaResponse {
signature: s.to_string(),
})),
@ -285,6 +285,7 @@ fn sign_and_send(
rpc: &RpcClient,
tx: &mut Transaction,
keys: Vec<&Keypair>,
skip_preflight: bool,
) -> Result<Signature, ClientError> {
let (recent_blockhash, _fee_calculator) = rpc.get_recent_blockhash()?;
@ -296,7 +297,7 @@ fn sign_and_send(
commitment: CommitmentLevel::Processed,
},
RpcSendTransactionConfig {
skip_preflight: false,
skip_preflight,
preflight_commitment: Some(CommitmentLevel::Processed),
encoding: None,
},