Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(axelar_gateway)!: upgrade versioned #225

Closed
wants to merge 41 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
1608b15
make event for interchain transfer consistent with EVM
Foivos Nov 15, 2024
38519fb
Merge remote-tracking branch 'origin/main' into feat/fix-its-intercha…
Foivos Nov 19, 2024
bf90514
added some event tests and added an event emission on receive_deploy_…
Foivos Nov 19, 2024
3c48734
add #[test-only] to only test inclusions
Foivos Nov 19, 2024
faa0ae7
fix test only
Foivos Nov 19, 2024
63075d6
Merge remote-tracking branch 'origin/main' into feat/fix-its-intercha…
Foivos Nov 20, 2024
f733742
added event finding in utils
Foivos Nov 20, 2024
adc67e5
added separate tests for empty and non-empty and tested more args
Foivos Nov 20, 2024
3cbeb9f
Merge remote-tracking branch 'origin/main' into feat/fix-its-intercha…
Foivos Nov 20, 2024
0c63e88
Merge remote-tracking branch 'origin/main' into feat/fix-its-intercha…
Foivos Nov 20, 2024
94dac9a
checking for event in the gateway
Foivos Nov 20, 2024
f874c10
Revert "checking for event in the gateway"
Foivos Nov 20, 2024
8f716bc
check for events
Foivos Nov 20, 2024
3c041ab
Merge remote-tracking branch 'origin/main' into feat/fix-its-intercha…
Foivos Nov 20, 2024
6e590a2
Merge remote-tracking branch 'origin/main' into feat/axelar_gateway_e…
Foivos Nov 20, 2024
b77670a
some renaming
Foivos Nov 20, 2024
7fa7386
Merge branch 'feat/fix-its-interchain-transfer-event' into feat/axela…
Foivos Nov 20, 2024
275232d
fix naming issue
Foivos Nov 20, 2024
b28be61
Merge remote-tracking branch 'origin/main' into feat/axelar_gateway_e…
Foivos Nov 20, 2024
d65578f
Merge remote-tracking branch 'origin/main' into feat/axelar_gateway_e…
Foivos Nov 20, 2024
76733ca
rename assert_single_event to assert_event
Foivos Nov 20, 2024
90cabf6
added an upgraded version for gateway
Foivos Nov 21, 2024
3b14178
renaming axelar_gateway_v1 to axelar_gateway
Foivos Nov 21, 2024
a5e899c
feat: add controlledTest function
maancham Nov 22, 2024
b4cde66
make gateway upgrade to versioned
Foivos Nov 25, 2024
c54515c
try adding more files
Foivos Nov 26, 2024
5777faf
add postinstall
Foivos Nov 26, 2024
66cf733
add files
Foivos Nov 26, 2024
65620d3
Merge remote-tracking branch 'origin/main' into feat/upgrade-testing
Foivos Nov 26, 2024
0b550c6
Merge remote-tracking branch 'origin/main' into feat/upgrade-testing
Foivos Nov 27, 2024
cfc6b27
Merge branch 'feat/upgrade-testing' into feat/upgrade-versioned
Foivos Dec 12, 2024
fde9d16
add allow and disallow functions back and fix tests
Foivos Dec 12, 2024
80196e6
update upgrade.md
Foivos Dec 12, 2024
f588fa3
Update the version to 2 and added a new field
Foivos Dec 13, 2024
393a494
add some changes for upgradability ot work with main
Foivos Dec 13, 2024
c690b4b
Merge remote-tracking branch 'origin/main' into feat/upgrade-testing
Foivos Dec 13, 2024
c3cd639
Merge branch 'feat/upgrade-testing' into feat/upgrade-versioned
Foivos Dec 13, 2024
e23e6cf
upgrade migrate signature
Foivos Dec 16, 2024
7bab656
Merge branch 'feat/upgrade-testing' into feat/upgrade-versioned
Foivos Dec 16, 2024
8aa28c1
added accessors for the new field
Foivos Dec 16, 2024
1e572d2
allow set_new_field and new_field functions by default
Foivos Dec 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## Expected post-Upgrade Behaviour

Nothing should work on the original package, and everything should work on the newer package.
75 changes: 53 additions & 22 deletions move/axelar_gateway/sources/gateway.move
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,14 @@
/// - CallApproval is checked to match the `Channel`.id
///
/// The Gateway object uses a versioned field to support upgradability. The
/// current implementation uses Gateway_v0.
/// current implementation uses Gateway_v1.
module axelar_gateway::gateway;

use axelar_gateway::auth::{Self, validate_proof};
use axelar_gateway::bytes32::{Self, Bytes32};
use axelar_gateway::channel::{Channel, ApprovedMessage};
use axelar_gateway::gateway_v0::{Self, Gateway_v0};
use axelar_gateway::gateway_v1::{Self, Gateway_v1};
use axelar_gateway::gateway_v0::{Gateway_v0};
use axelar_gateway::message_ticket::{Self, MessageTicket};
use axelar_gateway::owner_cap::{Self, OwnerCap};
use axelar_gateway::weighted_signers;
Expand All @@ -53,7 +54,7 @@ use version_control::version_control::{Self, VersionControl};
// -------
// Version
// -------
const VERSION: u64 = 0;
const VERSION: u64 = 2;

// -------
// Structs
Expand Down Expand Up @@ -88,7 +89,7 @@ entry fun setup(
) {
let inner = versioned::create(
VERSION,
gateway_v0::new(
gateway_v1::new(
operator,
table::new(ctx),
auth::setup(
Expand All @@ -103,6 +104,7 @@ entry fun setup(
ctx,
),
version_control(),
0,
),
ctx,
);
Expand All @@ -118,9 +120,9 @@ entry fun setup(
// Macros
// ------
/// This macro also uses version control to sinplify things a bit.
macro fun value($self: &Gateway, $function_name: vector<u8>): &Gateway_v0 {
macro fun value($self: &Gateway, $function_name: vector<u8>): &Gateway_v1 {
let gateway = $self;
let value = gateway.inner.load_value<Gateway_v0>();
let value = gateway.inner.load_value<Gateway_v1>();
value.version_control().check(VERSION, ascii::string($function_name));
value
}
Expand All @@ -129,9 +131,9 @@ macro fun value($self: &Gateway, $function_name: vector<u8>): &Gateway_v0 {
macro fun value_mut(
$self: &mut Gateway,
$function_name: vector<u8>,
): &mut Gateway_v0 {
): &mut Gateway_v1 {
let gateway = $self;
let value = gateway.inner.load_value_mut<Gateway_v0>();
let value = gateway.inner.load_value_mut<Gateway_v1>();
value.version_control().check(VERSION, ascii::string($function_name));
value
}
Expand Down Expand Up @@ -174,6 +176,19 @@ entry fun rotate_signers(
)
}

/// This function should only be called once
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if this is called, it'll still fail due to the type mismatch since Gateway_v0 isn't stored anymore, right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could call in many times in the same version, but it would still fail as there are checks

/// (checks should be made on versioned to ensure this)
/// It upgrades the version control to the new version control.
entry fun migrate(self: &mut Gateway, _: &OwnerCap, data: vector<u8>) {
let (v0, cap) = self.inner.remove_value_for_upgrade<Gateway_v0>();
let v1 = v0.migrate(version_control(), data);
self.inner.upgrade(
VERSION,
v1,
cap
);
}

entry fun allow_function(
self: &mut Gateway,
_: &OwnerCap,
Expand All @@ -194,6 +209,14 @@ entry fun disallow_function(
.disallow_function(version, function_name);
}

entry fun set_new_field(self: &mut Gateway, new_field: u64) {
self.value_mut!(b"set_new_field").set_new_field(new_field);
}

entry fun new_field(self: &Gateway): u64 {
self.value!(b"new_field").new_field()
}

// ----------------
// Public Functions
// ----------------
Expand Down Expand Up @@ -276,6 +299,8 @@ public fun take_approved_message(

fun version_control(): VersionControl {
version_control::new(vector[
vector[],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

keep some functions available to test different cases

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cannot

vector[],
vector[
b"approve_messages",
b"rotate_signers",
Expand All @@ -285,6 +310,8 @@ fun version_control(): VersionControl {
b"send_message",
b"allow_function",
b"disallow_function",
b"set_new_field",
b"new_field",
].map!(|function_name| function_name.to_ascii_string()),
])
}
Expand All @@ -311,7 +338,7 @@ public fun create_for_testing(
): Gateway {
let inner = versioned::create(
VERSION,
gateway_v0::new(
gateway_v1::new(
operator,
table::new(ctx),
auth::setup(
Expand All @@ -323,6 +350,7 @@ public fun create_for_testing(
ctx,
),
version_control(),
0,
),
ctx,
);
Expand All @@ -337,11 +365,13 @@ fun dummy(ctx: &mut TxContext): Gateway {
let mut rng = sui::random::new_generator_for_testing();
let inner = versioned::create(
VERSION,
gateway_v0::new(
gateway_v1::new(
sui::address::from_bytes(rng.generate_bytes(32)),
table::new(ctx),
auth::dummy(ctx),
version_control::new(vector[
vector[],
vector[],
vector[
b"approve_messages",
b"rotate_signers",
Expand All @@ -354,6 +384,7 @@ fun dummy(ctx: &mut TxContext): Gateway {
b"",
].map!(|function_name| function_name.to_ascii_string()),
]),
0,
),
ctx,
);
Expand All @@ -371,7 +402,7 @@ public fun destroy_for_testing(self: Gateway) {
} = self;
id.delete();

let value = inner.destroy<Gateway_v0>();
let value = inner.destroy<Gateway_v1>();
let (_, messages, signers, _) = value.destroy_for_testing();

let (_, table, _, _, _, _) = signers.destroy_for_testing();
Expand Down Expand Up @@ -436,7 +467,7 @@ fun test_setup() {
id.delete();

let (operator_result, messages, signers, _) = inner
.destroy<Gateway_v0>()
.destroy<Gateway_v1>()
.destroy_for_testing();

assert!(operator == operator_result);
Expand Down Expand Up @@ -510,7 +541,7 @@ fun test_setup_remaining_bytes() {
id.delete();

let (operator_result, messages, signers, _) = inner
.destroy<Gateway_v0>()
.destroy<Gateway_v1>()
.destroy_for_testing();

assert!(operator == operator_result);
Expand Down Expand Up @@ -667,7 +698,7 @@ fun test_approve_messages() {
let messages = vector<axelar_gateway::message::Message>[
axelar_gateway::message::dummy(),
];
let data_hash = gateway_v0::approve_messages_data_hash(messages);
let data_hash = gateway_v1::approve_messages_data_hash(messages);
let proof = generate_proof(
data_hash,
domain_separator,
Expand Down Expand Up @@ -717,7 +748,7 @@ fun test_approve_messages_remaining_data() {
ctx,
);
let messages = vector[axelar_gateway::message::dummy()];
let data_hash = gateway_v0::approve_messages_data_hash(messages);
let data_hash = gateway_v1::approve_messages_data_hash(messages);
let proof = generate_proof(
data_hash,
domain_separator,
Expand Down Expand Up @@ -781,7 +812,7 @@ fun test_rotate_signers() {

utils::assert_event<events::SignersRotated>();

let data_hash = gateway_v0::rotate_signers_data_hash(next_weighted_signers);
let data_hash = gateway_v1::rotate_signers_data_hash(next_weighted_signers);
let proof = generate_proof(
data_hash,
domain_separator,
Expand Down Expand Up @@ -853,7 +884,7 @@ fun test_rotate_signers_remaining_data_message_data() {
let mut message_data = bcs::to_bytes(&next_weighted_signers);
message_data.push_back(0);

let data_hash = gateway_v0::rotate_signers_data_hash(next_weighted_signers);
let data_hash = gateway_v1::rotate_signers_data_hash(next_weighted_signers);
let proof = generate_proof(
data_hash,
domain_separator,
Expand Down Expand Up @@ -915,7 +946,7 @@ fun test_rotate_signers_remaining_data_proof_data() {
ctx,
);

let data_hash = gateway_v0::rotate_signers_data_hash(next_weighted_signers);
let data_hash = gateway_v1::rotate_signers_data_hash(next_weighted_signers);
let proof = generate_proof(
data_hash,
domain_separator,
Expand All @@ -938,7 +969,7 @@ fun test_rotate_signers_remaining_data_proof_data() {
}

#[test]
#[expected_failure(abort_code = axelar_gateway::gateway_v0::ENotLatestSigners)]
#[expected_failure(abort_code = axelar_gateway::gateway_v1::ENotLatestSigners)]
fun test_rotate_signers_not_latest_signers() {
let mut rng = sui::random::new_generator_for_testing();
let ctx = &mut sui::tx_context::dummy();
Expand Down Expand Up @@ -987,7 +1018,7 @@ fun test_rotate_signers_not_latest_signers() {
let epoch = self.value_mut!(b"rotate_signers").signers_mut().epoch_mut();
*epoch = *epoch + 1;

let data_hash = gateway_v0::rotate_signers_data_hash(next_weighted_signers);
let data_hash = gateway_v1::rotate_signers_data_hash(next_weighted_signers);
let proof = generate_proof(
data_hash,
domain_separator,
Expand Down Expand Up @@ -1075,7 +1106,7 @@ fun test_allow_function() {
let ctx = &mut sui::tx_context::dummy();
let mut self = dummy(ctx);
let owner_cap = owner_cap::create(ctx);
let version = 0;
let version = VERSION;
let function_name = b"function_name".to_ascii_string();

self.allow_function(&owner_cap, version, function_name);
Expand All @@ -1089,7 +1120,7 @@ fun test_disallow_function() {
let ctx = &mut sui::tx_context::dummy();
let mut self = dummy(ctx);
let owner_cap = owner_cap::create(ctx);
let version = 0;
let version = VERSION;
let function_name = b"approve_messages".to_ascii_string();

self.disallow_function(&owner_cap, version, function_name);
Expand Down
Loading
Loading