Skip to content

Commit

Permalink
Bump polkadot node version (hyperledger-solang#1617)
Browse files Browse the repository at this point in the history
Upgrade the Polkadot node. In recent versions, the node (in debug mode)
logs any API calls and their results to debug buffer on its own. Removed
this feature because it was only relevant in the Polkadot target.
  • Loading branch information
xermicus authored Jan 12, 2024
1 parent 00bcabb commit 0f032dc
Show file tree
Hide file tree
Showing 31 changed files with 92 additions and 268 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ jobs:
# We can't run substrate node as a github actions service, since it requires
# command line arguments. See https://github.com/actions/runner/pull/1152
- name: Start substrate contracts node
run: echo id=$(docker run -d -p 9944:9944 ghcr.io/hyperledger/solang-substrate-ci:054bef6 substrate-contracts-node --dev --rpc-external) >> $GITHUB_OUTPUT
run: echo id=$(docker run -d -p 9944:9944 ghcr.io/hyperledger/solang-substrate-ci:ad6da01 substrate-contracts-node --dev --rpc-external -lwarn,runtime::contracts=trace) >> $GITHUB_OUTPUT
id: substrate
- uses: actions/download-artifact@v3
with:
Expand Down Expand Up @@ -390,7 +390,7 @@ jobs:
# We can't run substrate node as a github actions service, since it requires
# command line arguments. See https://github.com/actions/runner/pull/1152
- name: Start substrate
run: echo id=$(docker run -d -p 9944:9944 ghcr.io/hyperledger/solang-substrate-ci:054bef6 substrate-contracts-node --dev --rpc-external) >> $GITHUB_OUTPUT
run: echo id=$(docker run -d -p 9944:9944 ghcr.io/hyperledger/solang-substrate-ci:ad6da01 substrate-contracts-node --dev --rpc-external -lwarn,runtime::contracts=trace) >> $GITHUB_OUTPUT
id: substrate
- uses: actions/download-artifact@v3
with:
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ will be documented here.
### Changed
- **BREAKING** The non-standard extension of concatenating strings using the `+` operator
has been removed, use `string.concat()` instead. [seanyoung](https://github.com/seanyoung)
- Removed the `--no-log-api-return-codes` compile flag as this is now done by the runtime [xermicus](https://github.com/xermicus)

## v0.3.3 Atlantis

Expand Down
15 changes: 0 additions & 15 deletions docs/code_gen_options.rst
Original file line number Diff line number Diff line change
Expand Up @@ -177,21 +177,6 @@ Print Function
Solang provides a :ref:`print_function` which is enabled by default.
The ``no-print`` flag will instruct the compiler not to log debugging prints in the environment.

.. _no-log-api-return-codes:

Log runtime API call results
++++++++++++++++++++++++++++

Runtime API calls are not guaranteed to succeed.
By design, the low level results of these calls are abstracted away in Solidity.
For development purposes, it can be desirable to observe the low level return code of such calls.
The contract will print the return code of runtime calls by default, and this feature can be disabled by providing the
``--no-log-api-return-codes`` flag.

.. note::

This is only implemented for the Polkadot target.


.. _no-log-runtime-errors:

Expand Down
3 changes: 0 additions & 3 deletions docs/running.rst
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,6 @@ Options:
\-\-no\-cse
Disable the :ref:`common-subexpression-elimination` optimization

\-\-no\-log\-api\-return\-codes
Disable the :ref:`no-log-api-return-codes` debugging feature

\-\-no\-log\-runtime\-errors
Disable the :ref:`no-log-runtime-errors` debugging feature

Expand Down
5 changes: 4 additions & 1 deletion integration/polkadot/balances.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ describe('Deploy balances contract and test', () => {
let { output: contractRpcBal } = await query(conn, alice, contract, "getBalance");
let { data: { free: contractQueryBalBefore } } = await conn.query.system.account(String(deploy_contract.address));

expect(contractRpcBal?.toString()).toBe(contractQueryBalBefore.toString());
// The "Existential Deposit" (aka. minimum balance) is part of the free balance;
// to get the actual free balance from a contracts point of view we substract it.
const ED = 1000000000n;
expect(contractRpcBal?.toString()).toBe((contractQueryBalBefore.toBigInt() - ED).toString());

let gasLimit = await weight(conn, contract, "payMe", undefined, 1000000n);
let tx = contract.tx.payMe({ gasLimit, value: 1000000n });
Expand Down
2 changes: 1 addition & 1 deletion integration/polkadot/chain_extension.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import expect from 'expect';
import { weight, createConnection, deploy, transaction, aliceKeypair, query, } from './index';
import { createConnection, deploy, aliceKeypair, query, } from './index';
import { ContractPromise } from '@polkadot/api-contract';
import { daveKeypair } from './index';

Expand Down
13 changes: 8 additions & 5 deletions integration/polkadot/create_contract.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ describe('Deploy create_contract contract and test', () => {

let dry = await dry_run(conn, contract, "createChild");
// Expect the instantiation nonce to be present
const current_nonce = dry.debugMessage.split('\n')[0].split('=');
expect(current_nonce[0]).toEqual("call: instantiation_nonce");
const current_nonce = dry.debugMessage.split('\n')[2].split('=');
expect(current_nonce[0]).toContain("seal0::instantiation_nonce");

const gasLimit = dry.gasRequired;
let tx = contract.tx.createChild({ gasLimit });
Expand All @@ -51,8 +51,11 @@ describe('Deploy create_contract contract and test', () => {
expect(BigInt(1e15) - childBalance.toBigInt()).toBeLessThan(1e11);

// Expect the instantiation nonce to be present and to increase
const next_nonce = (await debug_buffer(conn, contract, "createChild")).split('\n')[0].split('=');
expect(next_nonce[0]).toEqual("call: instantiation_nonce");
expect(parseInt(current_nonce[1])).toBeLessThan(parseInt(next_nonce[1]));
const next_nonce = (await debug_buffer(conn, contract, "createChild")).split('\n')[2].split('=');
expect(next_nonce[0]).toContain("seal0::instantiation_nonce");

const current_nonce_value = parseInt(current_nonce[1].split('(')[1].split(')')[0]);
const next_nonce_value = parseInt(next_nonce[1].split('(')[1].split(')')[0]);
expect(current_nonce_value).toBeLessThan(next_nonce_value);
});
});
16 changes: 4 additions & 12 deletions integration/polkadot/debug_buffer_format.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,12 @@ describe('Deploy debug_buffer_format.sol and test the debug buffer formatting',
);

let res = await debug_buffer(conn, contract, "multiple_prints", [])
expect(res).toEqual(`print: Hello!,
call: seal_debug_message=0,
print: I call seal_debug_message under the hood!,
call: seal_debug_message=0,
`)
expect(res).toContain(`print: Hello!,`);
expect(res).toContain(`print: I call seal_debug_message under the hood!,`);

let res1 = await debug_buffer(conn, contract, "multiple_prints_then_revert", [])
expect(res1).toEqual(`print: Hello!,
call: seal_debug_message=0,
print: I call seal_debug_message under the hood!,
call: seal_debug_message=0,
runtime_error: sesa!!! revert encountered in debug_buffer_format.sol:10:9-26,
call: seal_debug_message=0,
`)
expect(res1).toContain(`print: Hello!,`);
expect(res1).toContain(`print: I call seal_debug_message under the hood!,`);

conn.disconnect();
});
Expand Down
4 changes: 2 additions & 2 deletions integration/polkadot/ink/caller/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ authors = ["Cyrill Leutwiler <cyrill@parity.io>"]
edition = "2021"

[dependencies]
ink = { version = "4.2.0", default-features = false }
ink = { version = "4.3.0", default-features = false }

scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] }
scale-info = { version = "2.6", default-features = false, features = ["derive"], optional = true }
scale-info = { version = "2.10", default-features = false, features = ["derive"], optional = true }

[lib]
path = "lib.rs"
Expand Down
12 changes: 6 additions & 6 deletions integration/polkadot/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"scripts": {
"test": "tsc; ts-mocha -t 20000 --exit *.spec.ts",
"build": "./build.sh",
"build-ink": "docker run --rm -v $(pwd)/ink/caller:/opt/contract ghcr.io/hyperledger/solang-substrate-ci:054bef6 cargo contract build --release --manifest-path /opt/contract/Cargo.toml"
"build-ink": "docker run --rm -v $(pwd)/ink/caller:/opt/contract ghcr.io/hyperledger/solang-substrate-ci:ad6da01 cargo contract build --release --manifest-path /opt/contract/Cargo.toml"
},
"contributors": [
{
Expand All @@ -30,11 +30,11 @@
"typescript": "^4.7"
},
"dependencies": {
"@polkadot/api": "^10.9",
"@polkadot/api-contract": "^10.9",
"@polkadot/keyring": "^12.3",
"@polkadot/types": "^10.9",
"@polkadot/util-crypto": "^12.3",
"@polkadot/api": "^10.11",
"@polkadot/api-contract": "^10.11",
"@polkadot/keyring": "^12.6",
"@polkadot/types": "^10.11",
"@polkadot/util-crypto": "^12.6",
"websnark": "git+https://github.com/tornadocash/websnark.git#4c0af6a8b65aabea3c09f377f63c44e7a58afa6d",
"snarkjs": "git+https://github.com/tornadocash/snarkjs.git#869181cfaf7526fe8972073d31655493a04326d5",
"circomlib": "git+https://github.com/tornadocash/circomlib.git#c372f14d324d57339c88451834bf2824e73bbdbc",
Expand Down
4 changes: 2 additions & 2 deletions integration/polkadot/release_version.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ describe('Deploy release_version.sol and test the debug buffer is empty', () =>

// The --release flag should remove all debugging features, making the debug buffer empty
let res = await debug_buffer(conn, contract, `print_then_error`, [20])
expect(res).toEqual("")
expect(res).not.toContain("Hello!")

let res2 = await debug_buffer(conn, contract, `print_then_error`, [0])
expect(res2).toEqual("")
expect(res).not.toContain("Hello!")
conn.disconnect();
});
});
2 changes: 1 addition & 1 deletion integration/subxt-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pallet-contracts-primitives = "24.0.0"
hex = "0.4.3"
num-bigint = "0.4.3"
once_cell = "1.17.2"
parity-scale-codec = { version = "3.5.0", features = ["derive"] }
parity-scale-codec = { version = "3.6.9", features = ["derive"] }
rand = "0.8.5"
serde_json = "1.0.96"
sp-keyring = "24.0.0"
Expand Down
Binary file modified integration/subxt-tests/metadata.scale
Binary file not shown.
7 changes: 6 additions & 1 deletion integration/subxt-tests/src/cases/destruct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,12 @@ async fn case() -> anyhow::Result<()> {
let contract_after = free_balance_of(&api, deployed.contract_address.clone()).await?;

assert_eq!(contract_after, 0);
assert_eq!(dave_after, dave_before + contract_before);

let existential_deposit = 1000000000;
assert_eq!(
dave_after,
dave_before + contract_before + existential_deposit
);

Ok(())
}
2 changes: 1 addition & 1 deletion integration/subxt-tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ pub async fn free_balance_of(api: &API, addr: AccountId32) -> anyhow::Result<u12
.fetch_or_default(&key)
.await?;

Ok(val.data.free)
Ok(val.data.free.saturating_sub(1000000000))
}

struct Contract {
Expand Down
10 changes: 0 additions & 10 deletions src/bin/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,6 @@ impl Compile {
}

// DebugFeatures args
"NOLOGAPIRETURNS" => {
self.debug_features.log_api_return_codes =
*matches.get_one::<bool>("NOLOGAPIRETURNS").unwrap()
}
"NOLOGRUNTIMEERRORS" => {
self.debug_features.log_runtime_errors =
*matches.get_one::<bool>("NOLOGRUNTIMEERRORS").unwrap()
Expand Down Expand Up @@ -329,10 +325,6 @@ pub struct CompilePackage {

#[derive(Args, Deserialize, Debug, PartialEq)]
pub struct DebugFeatures {
#[arg(name = "NOLOGAPIRETURNS", help = "Disable logging the return codes of runtime API calls in the environment", long = "no-log-api-return-codes", action = ArgAction::SetFalse)]
#[serde(default, rename(deserialize = "log-api-return-codes"))]
pub log_api_return_codes: bool,

#[arg(name = "NOLOGRUNTIMEERRORS", help = "Disable logging runtime errors in the environment", long = "no-log-runtime-errors", action = ArgAction::SetFalse)]
#[serde(default, rename(deserialize = "log-runtime-errors"))]
pub log_runtime_errors: bool,
Expand All @@ -353,7 +345,6 @@ pub struct DebugFeatures {
impl Default for DebugFeatures {
fn default() -> Self {
DebugFeatures {
log_api_return_codes: true,
log_runtime_errors: true,
log_prints: true,
generate_debug_info: false,
Expand Down Expand Up @@ -575,7 +566,6 @@ pub fn options_arg(debug: &DebugFeatures, optimizations: &Optimizations) -> Opti
common_subexpression_elimination: optimizations.common_subexpression_elimination,
generate_debug_information: debug.generate_debug_info,
opt_level,
log_api_return_codes: debug.log_api_return_codes && !debug.release,
log_runtime_errors: debug.log_runtime_errors && !debug.release,
log_prints: debug.log_prints && !debug.release,
#[cfg(feature = "wasm_opt")]
Expand Down
5 changes: 1 addition & 4 deletions src/bin/cli/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,11 @@ mod tests {
assert_eq!(compile_args.optimizations.opt_level.unwrap(), "aggressive");
}

command = "solang compile flipper.sol --target polkadot --no-log-runtime-errors --no-prints --no-log-api-return-codes -g --release".split(' ').collect();
command = "solang compile flipper.sol --target polkadot --no-log-runtime-errors --no-prints -g --release".split(' ').collect();
cli = Cli::parse_from(command);

if let Commands::Compile(compile_args) = cli.command {
assert!(compile_args.debug_features.generate_debug_info);
assert!(!compile_args.debug_features.log_api_return_codes);
assert!(!compile_args.debug_features.log_prints);
assert!(!compile_args.debug_features.log_runtime_errors);
assert!(compile_args.debug_features.release);
Expand Down Expand Up @@ -201,7 +200,6 @@ mod tests {
value_length: None
},
debug_features: cli::DebugFeatures {
log_api_return_codes: true,
log_runtime_errors: true,
log_prints: true,
generate_debug_info: false,
Expand Down Expand Up @@ -256,7 +254,6 @@ mod tests {
value_length: Some(31)
},
debug_features: cli::DebugFeatures {
log_api_return_codes: true,
log_runtime_errors: true,
log_prints: true,
generate_debug_info: false,
Expand Down
2 changes: 0 additions & 2 deletions src/codegen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ pub struct Options {
pub common_subexpression_elimination: bool,
pub generate_debug_information: bool,
pub opt_level: OptimizationLevel,
pub log_api_return_codes: bool,
pub log_runtime_errors: bool,
pub log_prints: bool,
#[cfg(feature = "wasm_opt")]
Expand All @@ -120,7 +119,6 @@ impl Default for Options {
common_subexpression_elimination: true,
generate_debug_information: false,
opt_level: OptimizationLevel::Default,
log_api_return_codes: false,
log_runtime_errors: false,
log_prints: true,
#[cfg(feature = "wasm_opt")]
Expand Down
72 changes: 0 additions & 72 deletions src/emit/polkadot/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use inkwell::AddressSpace;
use crate::codegen::dispatch::polkadot::DispatchType;
use crate::emit::functions::emit_functions;
use crate::emit::{Binary, TargetRuntime};
use crate::emit_context;

mod storage;
pub(super) mod target;
Expand Down Expand Up @@ -300,74 +299,3 @@ impl PolkadotTarget {
bin.builder.build_unreachable();
}
}

/// Print the return code of API calls to the debug buffer.
fn log_return_code(binary: &Binary, api: &'static str, code: IntValue) {
if !binary.options.log_api_return_codes {
return;
}

emit_context!(binary);

let fmt = format!("call: {api}=");
let msg = fmt.as_bytes();
let delimiter = b",\n";
let delimiter_length = delimiter.len();
let length = i32_const!(msg.len() as u64 + 16 + delimiter_length as u64);
let out_buf =
binary
.builder
.build_array_alloca(binary.context.i8_type(), length, "seal_ret_code_buf");
let mut out_buf_offset = out_buf;

let msg_string = binary.emit_global_string(&fmt, msg, true);
let msg_len = binary.context.i32_type().const_int(msg.len() as u64, false);
call!(
"__memcpy",
&[out_buf_offset.into(), msg_string.into(), msg_len.into()]
);
out_buf_offset = unsafe {
binary
.builder
.build_gep(binary.context.i8_type(), out_buf_offset, &[msg_len], "")
};

let code = binary
.builder
.build_int_z_extend(code, binary.context.i64_type(), "val_64bits");
out_buf_offset = call!("uint2dec", &[out_buf_offset.into(), code.into()])
.try_as_basic_value()
.left()
.unwrap()
.into_pointer_value();

let delimiter_string = binary.emit_global_string("delimiter", delimiter, true);
let lim_len = binary
.context
.i32_type()
.const_int(delimiter_length as u64, false);
call!(
"__memcpy",
&[
out_buf_offset.into(),
delimiter_string.into(),
lim_len.into()
]
);
out_buf_offset = unsafe {
binary
.builder
.build_gep(binary.context.i8_type(), out_buf_offset, &[lim_len], "")
};

let msg_len = binary.builder.build_int_sub(
binary
.builder
.build_ptr_to_int(out_buf_offset, binary.context.i32_type(), "out_buf_idx"),
binary
.builder
.build_ptr_to_int(out_buf, binary.context.i32_type(), "out_buf_ptr"),
"msg_len",
);
call!("debug_message", &[out_buf.into(), msg_len.into()]);
}
Loading

0 comments on commit 0f032dc

Please sign in to comment.