Skip to content

Commit 28396c1

Browse files
Release 3.6.4 (#940)
### Additions - Added a possibility to provide amount of gas for the `state_migration` callback in the `upgrade` transaction by @aleksuss. #937 --------- Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
1 parent 932412d commit 28396c1

File tree

9 files changed

+84
-54
lines changed

9 files changed

+84
-54
lines changed

CHANGES.md

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

88
## [Unreleased]
99

10+
## [3.6.4] 2024-07-22
11+
12+
### Additions
13+
14+
- Added a possibility to provide amount of gas for the `state_migration` callback in the `upgrade`
15+
transaction by [@aleksuss]. ([#937])
16+
17+
[#937]: https://github.com/aurora-is-near/aurora-engine/pull/937
18+
1019
## [3.6.3] 2024-04-16
1120

1221
### Additions
@@ -651,7 +660,8 @@ struct SubmitResult {
651660

652661
## [1.0.0] - 2021-05-12
653662

654-
[Unreleased]: https://github.com/aurora-is-near/aurora-engine/compare/3.6.3...develop
663+
[Unreleased]: https://github.com/aurora-is-near/aurora-engine/compare/3.6.4...develop
664+
[3.6.4]: https://github.com/aurora-is-near/aurora-engine/compare/3.6.3...3.6.4
655665
[3.6.3]: https://github.com/aurora-is-near/aurora-engine/compare/3.6.2...3.6.3
656666
[3.6.2]: https://github.com/aurora-is-near/aurora-engine/compare/3.6.1...3.6.2
657667
[3.6.1]: https://github.com/aurora-is-near/aurora-engine/compare/3.6.0...3.6.1

Cargo.lock

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

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.6.3
1+
3.6.4

engine-tests-connector/src/connector.rs

Lines changed: 16 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -222,15 +222,7 @@ async fn test_ft_transfer_call_eth() -> anyhow::Result<()> {
222222
);
223223

224224
let transfer_amount: U128 = 50.into();
225-
let fee: u128 = 30;
226-
let mut msg = U256::from(fee).as_byte_slice().to_vec();
227-
msg.append(
228-
&mut validate_eth_address(RECIPIENT_ETH_ADDRESS)
229-
.as_bytes()
230-
.to_vec(),
231-
);
232-
233-
let message = [CONTRACT_ACC, hex::encode(msg).as_str()].join(":");
225+
let message = ft_transfer_msg(CONTRACT_ACC, 30, RECIPIENT_ETH_ADDRESS);
234226
let memo: Option<String> = None;
235227
let res = user_acc
236228
.call(contract.engine_contract.id(), "ft_transfer_call")
@@ -288,7 +280,7 @@ async fn test_ft_transfer_call_without_fee() -> anyhow::Result<()> {
288280
);
289281

290282
let transfer_amount: U128 = 50.into();
291-
let message = RECIPIENT_ETH_ADDRESS;
283+
let message = ft_transfer_msg("relayer.root", 0, RECIPIENT_ETH_ADDRESS);
292284
let memo: Option<String> = None;
293285
let res = user_acc
294286
.call(contract.engine_contract.id(), "ft_transfer_call")
@@ -302,7 +294,7 @@ async fn test_ft_transfer_call_without_fee() -> anyhow::Result<()> {
302294
.deposit(ONE_YOCTO)
303295
.transact()
304296
.await?;
305-
assert!(res.is_success());
297+
assert!(res.is_success(), "{res:#?}");
306298

307299
assert_eq!(
308300
contract.get_eth_on_near_balance(user_acc.id()).await?.0,
@@ -592,14 +584,7 @@ async fn test_ft_transfer_call_without_relayer() -> anyhow::Result<()> {
592584
);
593585

594586
let transfer_amount: U128 = 50.into();
595-
let fee: u128 = 30;
596-
let mut msg = U256::from(fee).as_byte_slice().to_vec();
597-
let recipient_address = validate_eth_address(RECIPIENT_ETH_ADDRESS);
598-
msg.append(&mut recipient_address.as_bytes().to_vec());
599-
600-
let relayer_id = "relayer.root";
601-
let message = [relayer_id, hex::encode(msg).as_str()].join(":");
602-
587+
let message = ft_transfer_msg("relayer.root", 30, RECIPIENT_ETH_ADDRESS);
603588
let memo: Option<String> = None;
604589
let res = user_acc
605590
.call(contract.engine_contract.id(), "ft_transfer_call")
@@ -624,7 +609,9 @@ async fn test_ft_transfer_call_without_relayer() -> anyhow::Result<()> {
624609
transfer_amount.0
625610
);
626611
assert_eq!(
627-
contract.get_eth_balance(&recipient_address).await?,
612+
contract
613+
.get_eth_balance(&validate_eth_address(RECIPIENT_ETH_ADDRESS))
614+
.await?,
628615
transfer_amount.0
629616
);
630617
assert_eq!(contract.total_supply().await?, DEPOSITED_AMOUNT);
@@ -637,15 +624,7 @@ async fn test_ft_transfer_call_fee_greater_than_amount() -> anyhow::Result<()> {
637624
contract.call_deposit_eth_to_near().await?;
638625

639626
let transfer_amount: U128 = 10.into();
640-
let fee: u128 = 12;
641-
let mut msg = U256::from(fee).as_byte_slice().to_vec();
642-
msg.append(
643-
&mut validate_eth_address(RECIPIENT_ETH_ADDRESS)
644-
.as_bytes()
645-
.to_vec(),
646-
);
647-
let relayer_id = "relayer.root";
648-
let message = [relayer_id, hex::encode(msg).as_str()].join(":");
627+
let message = ft_transfer_msg("relayer.root", 12, RECIPIENT_ETH_ADDRESS);
649628
let memo: Option<String> = None;
650629
let user_acc = contract
651630
.create_sub_account(DEPOSITED_RECIPIENT_NAME)
@@ -1337,3 +1316,11 @@ async fn test_ft_metadata() -> anyhow::Result<()> {
13371316
assert_eq!(metadata.symbol, m.symbol);
13381317
Ok(())
13391318
}
1319+
1320+
fn ft_transfer_msg(relayer_id: &str, fee: u128, recipient: &str) -> String {
1321+
let mut msg = U256::from(fee).as_byte_slice().to_vec();
1322+
let recipient_address = validate_eth_address(recipient);
1323+
1324+
msg.extend(recipient_address.as_bytes());
1325+
[relayer_id, hex::encode(msg).as_str()].join(":")
1326+
}

engine-tests-connector/src/utils.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ pub struct TestContract {
4141
}
4242

4343
impl TestContract {
44-
pub async fn deploy_aurora_contract() -> anyhow::Result<(Contract, Contract, Account)> {
44+
async fn deploy_aurora_contract() -> anyhow::Result<(Contract, Contract, Account)> {
4545
use near_workspaces::{
4646
types::{KeyType, SecretKey},
4747
AccessKey,
@@ -141,6 +141,14 @@ impl TestContract {
141141
.await?;
142142
assert!(res.is_success());
143143

144+
let result = eth_connector_contract
145+
.call("pa_unpause_feature")
146+
.args_json(json!({ "key": "ALL" }))
147+
.max_gas()
148+
.transact()
149+
.await?;
150+
assert!(result.is_success(), "{result:#?}");
151+
144152
let chain_id = [0u8; 32];
145153
let res = engine_contract
146154
.call("new")

engine-tests/src/utils/workspace.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,15 @@ async fn init_eth_connector(aurora: &EngineContract) -> anyhow::Result<()> {
8585
.await?;
8686
assert!(result.is_success());
8787

88+
// By default, the contract is paused. So we need to unpause it.
89+
let result = contract
90+
.call("pa_unpause_feature")
91+
.args_json(json!({ "key": "ALL" }))
92+
.max_gas()
93+
.transact()
94+
.await?;
95+
assert!(result.is_success());
96+
8897
let result = aurora
8998
.set_eth_connector_contract_account(contract_account.id(), WithdrawSerializeType::Borsh)
9099
.transact()

engine-types/src/parameters/engine.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,15 @@ pub struct RelayerKeyArgs {
339339

340340
pub type FullAccessKeyArgs = RelayerKeyArgs;
341341

342+
/// Parameters for upgrading the contract.
343+
#[derive(Debug, Clone, Eq, PartialEq, BorshSerialize, BorshDeserialize)]
344+
pub struct UpgradeParams {
345+
/// Code for upgrading.
346+
pub code: Vec<u8>,
347+
/// Amount of gas for the state migration.
348+
pub state_migration_gas: Option<u64>,
349+
}
350+
342351
mod chain_id_deserialize {
343352
use crate::types::{u256_to_arr, RawU256};
344353
use primitive_types::U256;

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.6.3"
3+
version = "3.6.4"
44
authors.workspace = true
55
edition.workspace = true
66
homepage.workspace = true

engine/src/contract_methods/admin.rs

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use aurora_engine_sdk::{
2929
io::{StorageIntermediate, IO},
3030
promise::PromiseHandler,
3131
};
32-
use aurora_engine_types::parameters::engine::FullAccessKeyArgs;
32+
use aurora_engine_types::parameters::engine::{FullAccessKeyArgs, UpgradeParams};
3333
use aurora_engine_types::types::{NearGas, ZERO_YOCTO};
3434
use aurora_engine_types::{
3535
borsh::BorshDeserialize,
@@ -38,7 +38,7 @@ use aurora_engine_types::{
3838
NewCallArgs, PausePrecompilesCallArgs, RelayerKeyArgs, RelayerKeyManagerArgs,
3939
SetOwnerArgs, SetUpgradeDelayBlocksArgs, StartHashchainArgs,
4040
},
41-
promise::{PromiseAction, PromiseBatchAction, PromiseCreateArgs},
41+
promise::{PromiseAction, PromiseBatchAction},
4242
},
4343
storage::{self, KeyPrefix},
4444
types::{Address, Yocto},
@@ -48,7 +48,7 @@ use function_name::named;
4848

4949
const CODE_KEY: &[u8; 4] = b"CODE";
5050
const CODE_STAGE_KEY: &[u8; 10] = b"CODE_STAGE";
51-
const GAS_FOR_STATE_MIGRATION: NearGas = NearGas::new(100_000_000_000_000);
51+
const GAS_FOR_STATE_MIGRATION: NearGas = NearGas::new(50_000_000_000_000);
5252

5353
#[named]
5454
pub fn new<I: IO + Copy, E: Env>(mut io: I, env: &E) -> Result<(), ContractError> {
@@ -189,23 +189,30 @@ pub fn upgrade<I: IO + Copy, E: Env, H: PromiseHandler>(
189189
require_running(&state)?;
190190
require_owner_only(&state, &env.predecessor_account_id())?;
191191

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,
192+
let input = io.read_input().to_vec();
193+
let (code, state_migration_gas) = match UpgradeParams::try_from_slice(&input) {
194+
Ok(args) => (
195+
args.code,
196+
args.state_migration_gas
197+
.map_or(GAS_FOR_STATE_MIGRATION, NearGas::new),
198+
),
199+
Err(_) => (input, GAS_FOR_STATE_MIGRATION), // Backward compatibility
204200
};
205-
let promise_id = unsafe {
206-
let base_id = handler.promise_create_batch(&batch);
207-
handler.promise_attach_callback(base_id, &state_migration_callback)
201+
202+
let target_account_id = env.current_account_id();
203+
let batch = PromiseBatchAction {
204+
target_account_id,
205+
actions: vec![
206+
PromiseAction::DeployContract { code },
207+
PromiseAction::FunctionCall {
208+
name: "state_migration".to_string(),
209+
args: vec![],
210+
attached_yocto: ZERO_YOCTO,
211+
gas: state_migration_gas,
212+
},
213+
],
208214
};
215+
let promise_id = unsafe { handler.promise_create_batch(&batch) };
209216

210217
handler.promise_return(promise_id);
211218

0 commit comments

Comments
 (0)