Track optional persistence in guardian and terra

Also reformatting

Change-Id: Ibdc426aa09a74a6f564090bb838be1b037a9fce1
This commit is contained in:
Hendrik Hofstadt 2021-07-05 15:31:03 +02:00
parent 0004dd6c2a
commit 0f854dc08b
13 changed files with 38 additions and 29 deletions

View File

@ -16,4 +16,5 @@ type MessagePublication struct {
EmitterChain vaa.ChainID
EmitterAddress vaa.Address
Payload []byte
Persist bool
}

View File

@ -187,6 +187,7 @@ func (e *EthBridgeWatcher) Run(ctx context.Context) error {
EmitterChain: vaa.ChainIDEthereum,
EmitterAddress: PadAddress(ev.Sender),
Payload: ev.Payload,
Persist: ev.PersistMessage,
}
logger.Info("found new lockup transaction", zap.Stringer("tx", ev.Raw.TxHash),

View File

@ -173,6 +173,7 @@ func (s *SolanaWatcher) Run(ctx context.Context) error {
EmitterChain: vaa.ChainIDSolana,
EmitterAddress: proposal.EmitterAddress,
Payload: proposal.Payload,
Persist: proposal.Persist == 1,
}
solanaLockupsConfirmed.Inc()

View File

@ -178,10 +178,11 @@ func (e *BridgeWatcher) Run(ctx context.Context) error {
nonce := gjson.Get(json, "result.events.from_contract\\.message\\.nonce.0")
sequence := gjson.Get(json, "result.events.from_contract\\.message\\.sequence.0")
blockTime := gjson.Get(json, "result.events.from_contract\\.message\\.block_time.0")
persist := gjson.Get(json, "result.events.from_contract\\.message\\.persist.0")
txHash := gjson.Get(json, "result.events.tx\\.hash.0")
if payload.Exists() && sender.Exists() && chainId.Exists() && nonce.Exists() && sequence.Exists() &&
blockTime.Exists() && txHash.Exists() {
blockTime.Exists() && txHash.Exists() && persist.Exists() {
logger.Info("new message detected on terra",
zap.String("chainId", chainId.String()),
@ -190,6 +191,7 @@ func (e *BridgeWatcher) Run(ctx context.Context) error {
zap.String("nonce", nonce.String()),
zap.String("sequence", sequence.String()),
zap.String("blockTime", blockTime.String()),
zap.String("persist", persist.String()),
)
senderAddress, err := StringToAddress(sender.String())
@ -216,6 +218,7 @@ func (e *BridgeWatcher) Run(ctx context.Context) error {
EmitterChain: vaa.ChainIDTerra,
EmitterAddress: senderAddress,
Payload: payloadValue,
Persist: persist.Bool(),
}
e.msgChan <- messagePublication
terraLockupsConfirmed.Inc()

View File

@ -105,7 +105,7 @@ pub enum QueryMsg {
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
pub struct WrappedAssetInfoResponse {
pub asset_chain: u16, // Asset chain id
pub asset_chain: u16, // Asset chain id
pub asset_address: Binary, // Asset smart contract address in the original chain
pub bridge: HumanAddr, // Bridge address, authorized to mint and burn wrapped tokens
pub bridge: HumanAddr, // Bridge address, authorized to mint and burn wrapped tokens
}

View File

@ -1,7 +1,7 @@
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use cosmwasm_std::{CanonicalAddr, ReadonlyStorage, Storage, Binary};
use cosmwasm_std::{Binary, CanonicalAddr, ReadonlyStorage, Storage};
use cosmwasm_storage::{singleton, singleton_read, ReadonlySingleton, Singleton};
pub const KEY_WRAPPED_ASSET: &[u8] = b"wrappedAsset";
@ -9,9 +9,9 @@ pub const KEY_WRAPPED_ASSET: &[u8] = b"wrappedAsset";
// Created at initialization and reference original asset and bridge address
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
pub struct WrappedAssetInfo {
pub asset_chain: u16, // Asset chain id
pub asset_chain: u16, // Asset chain id
pub asset_address: Binary, // Asset smart contract address on the original chain
pub bridge: CanonicalAddr, // Bridge address, authorized to mint and burn wrapped tokens
pub bridge: CanonicalAddr, // Bridge address, authorized to mint and burn wrapped tokens
}
pub fn wrapped_asset_info<S: Storage>(storage: &mut S) -> Singleton<S, WrappedAssetInfo> {

View File

@ -2,7 +2,7 @@ static WASM: &[u8] =
include_bytes!("../../../target/wasm32-unknown-unknown/release/cw20_wrapped.wasm");
use cosmwasm_std::{
from_slice, Env, HandleResponse, HandleResult, HumanAddr, InitResponse, Uint128, Binary,
from_slice, Binary, Env, HandleResponse, HandleResult, HumanAddr, InitResponse, Uint128,
};
use cosmwasm_storage::to_length_prefixed;
use cosmwasm_vm::testing::{
@ -224,4 +224,4 @@ fn transfer_works() {
&TestAddress::RECIPIENT.value(),
&Uint128(123_123_000),
);
}
}

View File

@ -215,6 +215,7 @@ fn handle_create_asset_meta<S: Storage, A: Api, Q: Querier>(
msg: to_binary(&WormholeHandleMsg::PostMessage {
message: Binary::from(token_bridge_message.serialize()),
nonce,
persist: true,
})?,
// forward coins sent to this message
send: env.message.sent_funds.clone(),
@ -271,7 +272,7 @@ fn handle_governance_payload<S: Storage, A: Api, Q: Querier>(
let module: String = module.chars().filter(|c| !c.is_whitespace()).collect();
if module != "token_bridge" {
return Err(StdError::generic_err("this is not a valid module"))
return Err(StdError::generic_err("this is not a valid module"));
}
match gov_packet.action {
@ -482,6 +483,7 @@ fn handle_initiate_transfer<S: Storage, A: Api, Q: Querier>(
msg: to_binary(&WormholeHandleMsg::PostMessage {
message: Binary::from(token_bridge_message.serialize()),
nonce,
persist: true,
})?,
// forward coins sent to this message
send: env.message.sent_funds.clone(),

View File

@ -4,7 +4,6 @@ use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
pub struct InitMsg {
// governance contract details
pub gov_chain: u16,
pub gov_address: Binary,
@ -16,8 +15,6 @@ pub struct InitMsg {
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum HandleMsg {
RegisterAssetHook {
asset_id: Binary,
},
@ -37,7 +34,7 @@ pub enum HandleMsg {
CreateAssetMeta {
asset_address: HumanAddr,
nonce: u32,
}
},
}
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]

View File

@ -1,7 +1,7 @@
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use cosmwasm_std::{HumanAddr, StdResult, Storage, Binary};
use cosmwasm_std::{Binary, HumanAddr, StdResult, Storage};
use cosmwasm_storage::{
bucket, bucket_read, singleton, singleton_read, Bucket, ReadonlyBucket, ReadonlySingleton,
Singleton,
@ -9,7 +9,6 @@ use cosmwasm_storage::{
use wormhole::byte_utils::ByteUtils;
pub static CONFIG_KEY: &[u8] = b"config";
pub static WRAPPED_ASSET_KEY: &[u8] = b"wrapped_asset";
pub static WRAPPED_ASSET_ADDRESS_KEY: &[u8] = b"wrapped_asset_address";
@ -58,9 +57,6 @@ pub fn wrapped_asset_address_read<S: Storage>(storage: &S) -> ReadonlyBucket<S,
bucket_read(WRAPPED_ASSET_ADDRESS_KEY, storage)
}
pub struct Action;
impl Action {
@ -88,7 +84,7 @@ impl TokenBridgeMessage {
})
}
pub fn serialize(&self) ->Vec<u8> {
pub fn serialize(&self) -> Vec<u8> {
[self.action.to_be_bytes().to_vec(), self.payload.clone()].concat()
}
}
@ -193,7 +189,6 @@ pub struct RegisterChain {
}
impl RegisterChain {
pub fn deserialize(data: &Vec<u8>) -> StdResult<Self> {
let data = data.as_slice();
let chain_id = data.get_u16(0);
@ -201,8 +196,7 @@ impl RegisterChain {
Ok(RegisterChain {
chain_id,
chain_address
chain_address,
})
}
}
}

View File

@ -1,6 +1,6 @@
static WASM: &[u8] = include_bytes!("../../../target/wasm32-unknown-unknown/release/wormhole.wasm");
use cosmwasm_std::{from_slice, Env, HumanAddr, InitResponse, Coin};
use cosmwasm_std::{from_slice, Coin, Env, HumanAddr, InitResponse};
use cosmwasm_storage::to_length_prefixed;
use cosmwasm_vm::testing::{init, mock_env, mock_instance, MockApi, MockQuerier, MockStorage};
use cosmwasm_vm::{Api, Instance, Storage};

View File

@ -63,9 +63,11 @@ pub fn handle<S: Storage, A: Api, Q: Querier>(
msg: HandleMsg,
) -> StdResult<HandleResponse> {
match msg {
HandleMsg::PostMessage { message, nonce } => {
handle_post_message(deps, env, &message.as_slice(), nonce)
}
HandleMsg::PostMessage {
message,
nonce,
persist,
} => handle_post_message(deps, env, &message.as_slice(), nonce, persist),
HandleMsg::SubmitVAA { vaa } => handle_submit_vaa(deps, env, vaa.as_slice()),
}
}
@ -251,6 +253,7 @@ fn handle_post_message<S: Storage, A: Api, Q: Querier>(
env: Env,
message: &[u8],
nonce: u32,
persist: bool,
) -> StdResult<HandleResponse> {
let state = config_read(&deps.storage).load()?;
@ -273,6 +276,7 @@ fn handle_post_message<S: Storage, A: Api, Q: Querier>(
log("message.nonce", nonce),
log("message.sequence", sequence),
log("message.block_time", env.block.time),
log("message.persist", persist),
],
data: None,
})

View File

@ -16,8 +16,14 @@ pub struct InitMsg {
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum HandleMsg {
SubmitVAA { vaa: Binary },
PostMessage { message: Binary, nonce: u32 },
SubmitVAA {
vaa: Binary,
},
PostMessage {
message: Binary,
nonce: u32,
persist: bool,
},
}
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]