Skip to content

Commit

Permalink
Release 3.5.0 (#880)
Browse files Browse the repository at this point in the history
## 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>
  • Loading branch information
3 people committed Dec 6, 2023
1 parent 4e67385 commit dc3f3c3
Show file tree
Hide file tree
Showing 15 changed files with 157 additions and 30 deletions.
14 changes: 11 additions & 3 deletions .github/workflows/builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ name: Build
jobs:
build:
name: Build contracts
runs-on: [self-hosted, heavy]
runs-on: github-hosted-heavy-runner
strategy:
matrix:
profile: [mainnet, mainnet-silo, testnet, testnet-silo]
Expand All @@ -17,7 +17,15 @@ jobs:
git checkout -f $(git -c user.name=x -c user.email=x@x commit-tree $(git hash-object -t tree /dev/null) < /dev/null) || :
- name: Clone the repository
uses: actions/checkout@v3
- run: |
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
- name: Install cargo-make
run: cargo install --no-default-features --force cargo-make
- name: Compile smart contracts
run: |
cargo make --profile ${{ matrix.profile }} build-docker
cargo make --profile ${{ matrix.profile }} build-xcc-docker
- run: ls -lH bin/aurora-*${{ matrix.profile }}.wasm
Expand All @@ -29,7 +37,7 @@ jobs:

publish:
name: Publish contracts
runs-on: [self-hosted, heavy]
runs-on: github-hosted-heavy-runner
needs: build
steps:
- name: Download artifacts
Expand Down
17 changes: 16 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [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]: https://github.com/aurora-is-near/aurora-engine/pull/877
[#878]: https://github.com/aurora-is-near/aurora-engine/pull/878

## [3.4.0] 2023-11-28

### Additions
Expand Down Expand Up @@ -573,7 +587,8 @@ struct SubmitResult {

## [1.0.0] - 2021-05-12

[Unreleased]: https://github.com/aurora-is-near/aurora-engine/compare/3.4.0...develop
[Unreleased]: https://github.com/aurora-is-near/aurora-engine/compare/3.5.0...develop
[3.5.0]: https://github.com/aurora-is-near/aurora-engine/compare/3.5.0...3.4.0
[3.4.0]: https://github.com/aurora-is-near/aurora-engine/compare/3.3.1...3.4.0
[3.3.1]: https://github.com/aurora-is-near/aurora-engine/compare/3.3.0...3.3.1
[3.3.0]: https://github.com/aurora-is-near/aurora-engine/compare/3.2.0...3.3.0
Expand Down
10 changes: 5 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ skip_core_tasks = true
CARGO = "cargo"
ENGINE_CARGO_TARGET = "wasm32-unknown-unknown"
SWEEP_DAYS = 30
BUILDER_HASH_COMMIT = "00226858199419aaa8c99f756bd192851666fb36" # https://hub.docker.com/r/nearprotocol/contract-builder/tags

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

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

[tasks.test-contracts]
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.4.0
3.5.0
2 changes: 1 addition & 1 deletion engine-precompiles/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ serde_json.workspace = true
default = ["std"]
std = ["aurora-engine-types/std", "aurora-engine-sdk/std", "bn/std", "evm/std", "libsecp256k1/std", "ripemd/std", "sha2/std", "sha3/std", "ethabi/std"]
borsh-compat = ["aurora-engine-types/borsh-compat", "aurora-engine-sdk/borsh-compat"]
contract = []
contract = ["aurora-engine-sdk/contract"]
log = []
error_refund = []
ext-connector = []
23 changes: 23 additions & 0 deletions engine-tests/src/tests/upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,29 @@ use crate::utils::workspace::deploy_engine;

#[tokio::test]
async fn test_code_upgrade() {
let aurora = deploy_engine().await;
// do upgrade
let result = aurora
.upgrade(contract_bytes())
.max_gas()
.transact()
.await
.unwrap();
assert!(result.is_success());

// call a new method
let result = aurora
.as_raw_contract()
.view("some_new_fancy_function")
.await
.unwrap();

let output: [u32; 7] = result.borsh().unwrap();
assert_eq!(output, [3, 1, 4, 1, 5, 9, 2]);
}

#[tokio::test]
async fn test_code_upgrade_with_stage() {
let aurora = deploy_engine().await;
// do upgrade
let result = aurora
Expand Down
1 change: 1 addition & 0 deletions engine-transactions/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ hex.workspace = true
[features]
std = ["aurora-engine-types/std", "aurora-engine-sdk/std", "aurora-engine-precompiles/std", "evm/std", "rlp/std"]
impl-serde = ["aurora-engine-types/impl-serde", "serde"]
contract = ["aurora-engine-sdk/contract", "aurora-engine-precompiles/contract"]
2 changes: 1 addition & 1 deletion engine-types/src/parameters/xcc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub struct WithdrawWnearToRouterArgs {
pub struct CodeVersion(pub u32);

impl CodeVersion {
pub const ONE: Self = Self(1);
pub const ZERO: Self = Self(0);

#[must_use]
pub const fn increment(self) -> Self {
Expand Down
20 changes: 12 additions & 8 deletions engine-workspace/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ use crate::operation::{
CallSetEthConnectorContractAccount, CallSetEthConnectorContractData, CallSetFixedGas,
CallSetKeyManager, CallSetOwner, CallSetPausedFlags, CallSetSiloParams, CallSetWhitelistStatus,
CallStageUpgrade, CallStateMigration, CallStorageDeposit, CallStorageUnregister,
CallStorageWithdraw, CallSubmit, CallWithdraw, ViewAccountsCounter, ViewBalance, ViewBlockHash,
ViewBridgeProver, ViewChainId, ViewCode, ViewErc20FromNep141, ViewFactoryWnearAddress,
ViewFtBalanceOf, ViewFtBalanceOfEth, ViewFtMetadata, ViewFtTotalEthSupplyOnAurora,
ViewFtTotalEthSupplyOnNear, ViewFtTotalSupply, ViewGetErc20Metadata,
ViewGetEthConnectorContractAccount, ViewGetFixedGas, ViewGetSiloParams, ViewGetWhitelistStatus,
ViewIsUsedProof, ViewNep141FromErc20, ViewNonce, ViewOwner, ViewPausedFlags,
ViewPausedPrecompiles, ViewStorageAt, ViewStorageBalanceOf, ViewUpgradeIndex, ViewVersion,
ViewView,
CallStorageWithdraw, CallSubmit, CallUpgrade, CallWithdraw, ViewAccountsCounter, ViewBalance,
ViewBlockHash, ViewBridgeProver, ViewChainId, ViewCode, ViewErc20FromNep141,
ViewFactoryWnearAddress, ViewFtBalanceOf, ViewFtBalanceOfEth, ViewFtMetadata,
ViewFtTotalEthSupplyOnAurora, ViewFtTotalEthSupplyOnNear, ViewFtTotalSupply,
ViewGetErc20Metadata, ViewGetEthConnectorContractAccount, ViewGetFixedGas, ViewGetSiloParams,
ViewGetWhitelistStatus, ViewIsUsedProof, ViewNep141FromErc20, ViewNonce, ViewOwner,
ViewPausedFlags, ViewPausedPrecompiles, ViewStorageAt, ViewStorageBalanceOf, ViewUpgradeIndex,
ViewVersion, ViewView,
};
use crate::transaction::{CallTransaction, ViewTransaction};
use aurora_engine_types::account_id::AccountId;
Expand Down Expand Up @@ -267,6 +267,10 @@ impl EngineContract {
CallFactorySetWNearAddress::call(&self.contract).args_borsh(address)
}

pub fn upgrade(&self, bytes: Vec<u8>) -> CallUpgrade {
CallUpgrade::call(&self.contract).args(bytes)
}

pub fn stage_upgrade(&self, bytes: Vec<u8>) -> CallStageUpgrade {
CallStageUpgrade::call(&self.contract).args(bytes)
}
Expand Down
3 changes: 3 additions & 0 deletions engine-workspace/src/operation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ impl_call_return![
(CallDeployUpgrade, Call::DeployUpgrade),
(CallResumePrecompiles, Call::ResumePrecompiles),
(CallPausePrecompiles, Call::PausePrecompiles),
(CallUpgrade, Call::Upgrade),
(CallStageUpgrade, Call::StageUpgrade),
(CallStateMigration, Call::StateMigration),
(CallMintAccount, Call::MintAccount),
Expand Down Expand Up @@ -127,6 +128,7 @@ pub(crate) enum Call {
StorageUnregister,
StorageWithdraw,
PausePrecompiles,
Upgrade,
StageUpgrade,
DeployUpgrade,
StateMigration,
Expand Down Expand Up @@ -176,6 +178,7 @@ impl AsRef<str> for Call {
Call::StorageUnregister => "storage_unregister",
Call::StorageWithdraw => "storage_withdraw",
Call::PausePrecompiles => "pause_precompiles",
Call::Upgrade => "upgrade",
Call::StageUpgrade => "stage_upgrade",
Call::DeployUpgrade => "deploy_upgrade",
Call::StateMigration => "state_migration",
Expand Down
2 changes: 1 addition & 1 deletion engine/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "aurora-engine"
version = "3.4.0"
version = "3.5.0"
authors.workspace = true
edition.workspace = true
homepage.workspace = true
Expand Down
38 changes: 36 additions & 2 deletions engine/src/contract_methods/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,25 @@ use aurora_engine_sdk::{
promise::PromiseHandler,
};
use aurora_engine_types::parameters::engine::FullAccessKeyArgs;
use aurora_engine_types::types::{NearGas, ZERO_YOCTO};
use aurora_engine_types::{
borsh::BorshDeserialize,
parameters::{
engine::{
NewCallArgs, PausePrecompilesCallArgs, RelayerKeyArgs, RelayerKeyManagerArgs,
SetOwnerArgs, SetUpgradeDelayBlocksArgs, StartHashchainArgs,
},
promise::{PromiseAction, PromiseBatchAction},
promise::{PromiseAction, PromiseBatchAction, PromiseCreateArgs},
},
storage::{self, KeyPrefix},
types::{Address, Yocto},
vec,
vec, ToString,
};
use function_name::named;

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

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

pub fn upgrade<I: IO + Copy, E: Env, H: PromiseHandler>(
io: I,
env: &E,
handler: &mut H,
) -> Result<(), ContractError> {
let state = state::get_state(&io)?;
require_running(&state)?;
require_owner_only(&state, &env.predecessor_account_id())?;

let code = io.read_input().to_vec();
let current_account_id = env.current_account_id();
let batch = PromiseBatchAction {
target_account_id: current_account_id.clone(),
actions: vec![PromiseAction::DeployContract { code }],
};
let state_migration_callback = PromiseCreateArgs {
target_account_id: current_account_id,
method: "state_migration".to_string(),
args: vec![],
attached_balance: ZERO_YOCTO,
attached_gas: GAS_FOR_STATE_MIGRATION,
};
let promise_id = unsafe {
let base_id = handler.promise_create_batch(&batch);
handler.promise_attach_callback(base_id, &state_migration_callback)
};

handler.promise_return(promise_id);

Ok(())
}

#[named]
pub fn resume_precompiles<I: IO + Copy, E: Env>(io: I, env: &E) -> Result<(), ContractError> {
with_hashchain(io, env, function_name!(), |io| {
Expand Down
12 changes: 12 additions & 0 deletions engine/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,18 @@ mod contract {
.sdk_unwrap();
}

/// Upgrade the contract with the provided code bytes.
#[no_mangle]
pub extern "C" fn upgrade() {
let io = Runtime;
let env = Runtime;
let mut handler = Runtime;

contract_methods::admin::upgrade(io, &env, &mut handler)
.map_err(ContractError::msg)
.sdk_unwrap();
}

/// Stage new code for deployment.
#[no_mangle]
pub extern "C" fn stage_upgrade() {
Expand Down

0 comments on commit dc3f3c3

Please sign in to comment.