Skip to content

Commit dc3f3c3

Browse files
aleksussbirchmddependabot[bot]
committed
Release 3.5.0 (#880)
## 3.5.0 2023-12-06 ### Additions - Added a new transaction `upgrade` which allows upgrading the contract and invoking the `state_migration` callback with one call by [@aleksuss]. ([#878]) ### Fixes - Updated the logic of upgrading XCC router which works properly on both `mainnet` and `testnet` by [@birchmd]. ([#877]) [#877]: #877 [#878]: #878 --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: Michael Birch <michael.birch@aurora.dev> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
1 parent 4e67385 commit dc3f3c3

File tree

15 files changed

+157
-30
lines changed

15 files changed

+157
-30
lines changed

.github/workflows/builds.yml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ name: Build
77
jobs:
88
build:
99
name: Build contracts
10-
runs-on: [self-hosted, heavy]
10+
runs-on: github-hosted-heavy-runner
1111
strategy:
1212
matrix:
1313
profile: [mainnet, mainnet-silo, testnet, testnet-silo]
@@ -17,7 +17,15 @@ jobs:
1717
git checkout -f $(git -c user.name=x -c user.email=x@x commit-tree $(git hash-object -t tree /dev/null) < /dev/null) || :
1818
- name: Clone the repository
1919
uses: actions/checkout@v3
20-
- run: |
20+
- name: Install Rust
21+
uses: actions-rs/toolchain@v1
22+
with:
23+
toolchain: stable
24+
override: true
25+
- name: Install cargo-make
26+
run: cargo install --no-default-features --force cargo-make
27+
- name: Compile smart contracts
28+
run: |
2129
cargo make --profile ${{ matrix.profile }} build-docker
2230
cargo make --profile ${{ matrix.profile }} build-xcc-docker
2331
- run: ls -lH bin/aurora-*${{ matrix.profile }}.wasm
@@ -29,7 +37,7 @@ jobs:
2937

3038
publish:
3139
name: Publish contracts
32-
runs-on: [self-hosted, heavy]
40+
runs-on: github-hosted-heavy-runner
3341
needs: build
3442
steps:
3543
- name: Download artifacts

CHANGES.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## [3.5.0] 2023-12-06
11+
12+
### Additions
13+
14+
- Added a new transaction `upgrade` which allows upgrading the contract and invoking the `state_migration` callback
15+
with one call by [@aleksuss]. ([#878])
16+
17+
### Fixes
18+
19+
- Updated the logic of upgrading XCC router which works properly on both `mainnet` and `testnet` by [@birchmd]. ([#877])
20+
21+
[#877]: https://github.com/aurora-is-near/aurora-engine/pull/877
22+
[#878]: https://github.com/aurora-is-near/aurora-engine/pull/878
23+
1024
## [3.4.0] 2023-11-28
1125

1226
### Additions
@@ -573,7 +587,8 @@ struct SubmitResult {
573587

574588
## [1.0.0] - 2021-05-12
575589

576-
[Unreleased]: https://github.com/aurora-is-near/aurora-engine/compare/3.4.0...develop
590+
[Unreleased]: https://github.com/aurora-is-near/aurora-engine/compare/3.5.0...develop
591+
[3.5.0]: https://github.com/aurora-is-near/aurora-engine/compare/3.5.0...3.4.0
577592
[3.4.0]: https://github.com/aurora-is-near/aurora-engine/compare/3.3.1...3.4.0
578593
[3.3.1]: https://github.com/aurora-is-near/aurora-engine/compare/3.3.0...3.3.1
579594
[3.3.0]: https://github.com/aurora-is-near/aurora-engine/compare/3.2.0...3.3.0

Cargo.lock

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Makefile.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ skip_core_tasks = true
1616
CARGO = "cargo"
1717
ENGINE_CARGO_TARGET = "wasm32-unknown-unknown"
1818
SWEEP_DAYS = 30
19+
BUILDER_HASH_COMMIT = "00226858199419aaa8c99f756bd192851666fb36" # https://hub.docker.com/r/nearprotocol/contract-builder/tags
1920

2021
[tasks.sweep]
2122
category = "Cleanup"
@@ -319,7 +320,7 @@ run_task = "build-engine-flow-docker"
319320
[tasks.build-docker]
320321
category = "Build"
321322
script = '''
322-
docker run --volume $PWD:/host -w /host -i --rm nearprotocol/contract-builder:master-9b27b37941a4419acdba3b8d5fd1d0ac8c99b37e-amd64 ./scripts/docker-entrypoint.sh ${PROFILE}
323+
docker run --volume $PWD:/host -w /host -i --rm nearprotocol/contract-builder:master-${BUILDER_HASH_COMMIT}-amd64 ./scripts/docker-entrypoint.sh ${PROFILE}
323324
'''
324325

325326
[tasks.build-xcc-router-docker-inner]
@@ -332,7 +333,7 @@ run_task = "build-xcc-router-flow-docker"
332333
condition = { profiles = ["mainnet", "testnet"] }
333334
category = "Build"
334335
script = '''
335-
docker run --volume $PWD:/host -w /host -i --rm nearprotocol/contract-builder:master-9b27b37941a4419acdba3b8d5fd1d0ac8c99b37e-amd64 ./scripts/docker-xcc-router-entrypoint.sh ${PROFILE}
336+
docker run --volume $PWD:/host -w /host -i --rm nearprotocol/contract-builder:master-${BUILDER_HASH_COMMIT}-amd64 ./scripts/docker-xcc-router-entrypoint.sh ${PROFILE}
336337
'''
337338

338339
[tasks.test-contracts]

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.4.0
1+
3.5.0

engine-precompiles/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ serde_json.workspace = true
3434
default = ["std"]
3535
std = ["aurora-engine-types/std", "aurora-engine-sdk/std", "bn/std", "evm/std", "libsecp256k1/std", "ripemd/std", "sha2/std", "sha3/std", "ethabi/std"]
3636
borsh-compat = ["aurora-engine-types/borsh-compat", "aurora-engine-sdk/borsh-compat"]
37-
contract = []
37+
contract = ["aurora-engine-sdk/contract"]
3838
log = []
3939
error_refund = []
4040
ext-connector = []

engine-tests/src/tests/upgrade.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,29 @@ use crate::utils::workspace::deploy_engine;
44

55
#[tokio::test]
66
async fn test_code_upgrade() {
7+
let aurora = deploy_engine().await;
8+
// do upgrade
9+
let result = aurora
10+
.upgrade(contract_bytes())
11+
.max_gas()
12+
.transact()
13+
.await
14+
.unwrap();
15+
assert!(result.is_success());
16+
17+
// call a new method
18+
let result = aurora
19+
.as_raw_contract()
20+
.view("some_new_fancy_function")
21+
.await
22+
.unwrap();
23+
24+
let output: [u32; 7] = result.borsh().unwrap();
25+
assert_eq!(output, [3, 1, 4, 1, 5, 9, 2]);
26+
}
27+
28+
#[tokio::test]
29+
async fn test_code_upgrade_with_stage() {
730
let aurora = deploy_engine().await;
831
// do upgrade
932
let result = aurora

engine-transactions/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ hex.workspace = true
2424
[features]
2525
std = ["aurora-engine-types/std", "aurora-engine-sdk/std", "aurora-engine-precompiles/std", "evm/std", "rlp/std"]
2626
impl-serde = ["aurora-engine-types/impl-serde", "serde"]
27+
contract = ["aurora-engine-sdk/contract", "aurora-engine-precompiles/contract"]

engine-types/src/parameters/xcc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pub struct WithdrawWnearToRouterArgs {
2727
pub struct CodeVersion(pub u32);
2828

2929
impl CodeVersion {
30-
pub const ONE: Self = Self(1);
30+
pub const ZERO: Self = Self(0);
3131

3232
#[must_use]
3333
pub const fn increment(self) -> Self {

engine-workspace/src/contract.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ use crate::operation::{
1111
CallSetEthConnectorContractAccount, CallSetEthConnectorContractData, CallSetFixedGas,
1212
CallSetKeyManager, CallSetOwner, CallSetPausedFlags, CallSetSiloParams, CallSetWhitelistStatus,
1313
CallStageUpgrade, CallStateMigration, CallStorageDeposit, CallStorageUnregister,
14-
CallStorageWithdraw, CallSubmit, CallWithdraw, ViewAccountsCounter, ViewBalance, ViewBlockHash,
15-
ViewBridgeProver, ViewChainId, ViewCode, ViewErc20FromNep141, ViewFactoryWnearAddress,
16-
ViewFtBalanceOf, ViewFtBalanceOfEth, ViewFtMetadata, ViewFtTotalEthSupplyOnAurora,
17-
ViewFtTotalEthSupplyOnNear, ViewFtTotalSupply, ViewGetErc20Metadata,
18-
ViewGetEthConnectorContractAccount, ViewGetFixedGas, ViewGetSiloParams, ViewGetWhitelistStatus,
19-
ViewIsUsedProof, ViewNep141FromErc20, ViewNonce, ViewOwner, ViewPausedFlags,
20-
ViewPausedPrecompiles, ViewStorageAt, ViewStorageBalanceOf, ViewUpgradeIndex, ViewVersion,
21-
ViewView,
14+
CallStorageWithdraw, CallSubmit, CallUpgrade, CallWithdraw, ViewAccountsCounter, ViewBalance,
15+
ViewBlockHash, ViewBridgeProver, ViewChainId, ViewCode, ViewErc20FromNep141,
16+
ViewFactoryWnearAddress, ViewFtBalanceOf, ViewFtBalanceOfEth, ViewFtMetadata,
17+
ViewFtTotalEthSupplyOnAurora, ViewFtTotalEthSupplyOnNear, ViewFtTotalSupply,
18+
ViewGetErc20Metadata, ViewGetEthConnectorContractAccount, ViewGetFixedGas, ViewGetSiloParams,
19+
ViewGetWhitelistStatus, ViewIsUsedProof, ViewNep141FromErc20, ViewNonce, ViewOwner,
20+
ViewPausedFlags, ViewPausedPrecompiles, ViewStorageAt, ViewStorageBalanceOf, ViewUpgradeIndex,
21+
ViewVersion, ViewView,
2222
};
2323
use crate::transaction::{CallTransaction, ViewTransaction};
2424
use aurora_engine_types::account_id::AccountId;
@@ -267,6 +267,10 @@ impl EngineContract {
267267
CallFactorySetWNearAddress::call(&self.contract).args_borsh(address)
268268
}
269269

270+
pub fn upgrade(&self, bytes: Vec<u8>) -> CallUpgrade {
271+
CallUpgrade::call(&self.contract).args(bytes)
272+
}
273+
270274
pub fn stage_upgrade(&self, bytes: Vec<u8>) -> CallStageUpgrade {
271275
CallStageUpgrade::call(&self.contract).args(bytes)
272276
}

engine-workspace/src/operation.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ impl_call_return![
3636
(CallDeployUpgrade, Call::DeployUpgrade),
3737
(CallResumePrecompiles, Call::ResumePrecompiles),
3838
(CallPausePrecompiles, Call::PausePrecompiles),
39+
(CallUpgrade, Call::Upgrade),
3940
(CallStageUpgrade, Call::StageUpgrade),
4041
(CallStateMigration, Call::StateMigration),
4142
(CallMintAccount, Call::MintAccount),
@@ -127,6 +128,7 @@ pub(crate) enum Call {
127128
StorageUnregister,
128129
StorageWithdraw,
129130
PausePrecompiles,
131+
Upgrade,
130132
StageUpgrade,
131133
DeployUpgrade,
132134
StateMigration,
@@ -176,6 +178,7 @@ impl AsRef<str> for Call {
176178
Call::StorageUnregister => "storage_unregister",
177179
Call::StorageWithdraw => "storage_withdraw",
178180
Call::PausePrecompiles => "pause_precompiles",
181+
Call::Upgrade => "upgrade",
179182
Call::StageUpgrade => "stage_upgrade",
180183
Call::DeployUpgrade => "deploy_upgrade",
181184
Call::StateMigration => "state_migration",

engine/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "aurora-engine"
3-
version = "3.4.0"
3+
version = "3.5.0"
44
authors.workspace = true
55
edition.workspace = true
66
homepage.workspace = true

engine/src/contract_methods/admin.rs

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,23 +30,25 @@ use aurora_engine_sdk::{
3030
promise::PromiseHandler,
3131
};
3232
use aurora_engine_types::parameters::engine::FullAccessKeyArgs;
33+
use aurora_engine_types::types::{NearGas, ZERO_YOCTO};
3334
use aurora_engine_types::{
3435
borsh::BorshDeserialize,
3536
parameters::{
3637
engine::{
3738
NewCallArgs, PausePrecompilesCallArgs, RelayerKeyArgs, RelayerKeyManagerArgs,
3839
SetOwnerArgs, SetUpgradeDelayBlocksArgs, StartHashchainArgs,
3940
},
40-
promise::{PromiseAction, PromiseBatchAction},
41+
promise::{PromiseAction, PromiseBatchAction, PromiseCreateArgs},
4142
},
4243
storage::{self, KeyPrefix},
4344
types::{Address, Yocto},
44-
vec,
45+
vec, ToString,
4546
};
4647
use function_name::named;
4748

4849
const CODE_KEY: &[u8; 4] = b"CODE";
4950
const CODE_STAGE_KEY: &[u8; 10] = b"CODE_STAGE";
51+
const GAS_FOR_STATE_MIGRATION: NearGas = NearGas::new(100_000_000_000_000);
5052

5153
#[named]
5254
pub fn new<I: IO + Copy, E: Env>(mut io: I, env: &E) -> Result<(), ContractError> {
@@ -178,6 +180,38 @@ pub fn stage_upgrade<I: IO + Copy, E: Env>(io: I, env: &E) -> Result<(), Contrac
178180
})
179181
}
180182

183+
pub fn upgrade<I: IO + Copy, E: Env, H: PromiseHandler>(
184+
io: I,
185+
env: &E,
186+
handler: &mut H,
187+
) -> Result<(), ContractError> {
188+
let state = state::get_state(&io)?;
189+
require_running(&state)?;
190+
require_owner_only(&state, &env.predecessor_account_id())?;
191+
192+
let code = io.read_input().to_vec();
193+
let current_account_id = env.current_account_id();
194+
let batch = PromiseBatchAction {
195+
target_account_id: current_account_id.clone(),
196+
actions: vec![PromiseAction::DeployContract { code }],
197+
};
198+
let state_migration_callback = PromiseCreateArgs {
199+
target_account_id: current_account_id,
200+
method: "state_migration".to_string(),
201+
args: vec![],
202+
attached_balance: ZERO_YOCTO,
203+
attached_gas: GAS_FOR_STATE_MIGRATION,
204+
};
205+
let promise_id = unsafe {
206+
let base_id = handler.promise_create_batch(&batch);
207+
handler.promise_attach_callback(base_id, &state_migration_callback)
208+
};
209+
210+
handler.promise_return(promise_id);
211+
212+
Ok(())
213+
}
214+
181215
#[named]
182216
pub fn resume_precompiles<I: IO + Copy, E: Env>(io: I, env: &E) -> Result<(), ContractError> {
183217
with_hashchain(io, env, function_name!(), |io| {

engine/src/lib.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,18 @@ mod contract {
182182
.sdk_unwrap();
183183
}
184184

185+
/// Upgrade the contract with the provided code bytes.
186+
#[no_mangle]
187+
pub extern "C" fn upgrade() {
188+
let io = Runtime;
189+
let env = Runtime;
190+
let mut handler = Runtime;
191+
192+
contract_methods::admin::upgrade(io, &env, &mut handler)
193+
.map_err(ContractError::msg)
194+
.sdk_unwrap();
195+
}
196+
185197
/// Stage new code for deployment.
186198
#[no_mangle]
187199
pub extern "C" fn stage_upgrade() {

0 commit comments

Comments
 (0)