Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Regular contracts are far more popular, so this should be the first option
8aaaf64 to
8223c78
Compare
| crate::commands::contract::download_wasm::ContractType::Global, | ||
| &receiver_id, | ||
| network_config, | ||
| near_primitives::types::BlockReference::latest(), |
There was a problem hiding this comment.
This is a workaround. Contract hash is not accessible at the block height with deploy-global transaction
https://testnet.nearblocks.io/txns/7iScLbaNApB47WwMhANr8NnddZaRzmNXHRqd5D2HjAnd
Contract was deployed at block 220576516, but code wasn't accessible until 220576518. Is it expected? What will be the best fix? Is it reliable to add always 2 blocks or does it fluctuate?
There was a problem hiding this comment.
Is it expected?
Yes, transaction is first converted into a receipt, and the receipt is executed in the following blocks.
Is it reliable to add always 2 blocks or does it fluctuate?
Nope, we need to use the block where the receipt execution outcomes are recorded. Check the tx status output for the receipt_outcomes, and use the block hash of the first receipt outcome.
There was a problem hiding this comment.
Check the tx status output for the receipt_outcomes, and use the block hash of the first receipt outcome.
The only receipt_outcome in the transaction has block height ...516. I've sent a message to protocol team to get some clarity
There was a problem hiding this comment.
I'll stick around with the option of simple loop to go through each block trying to fetch code
More information from the protocol team:
"there is at most 1 global contract distribution receipt in flight per global contract. Once a distribution receipt is processed on a destination shard, it checks on which shards the global contract was not distributed yet and creates a new receipt for one of those shards. The process keeps being repeated until all shards have the global contract, so the distribution can span multiple blocks"
"the distribution receipts are executed outside of the normal action receipt flow, so they don't have outcomes"
"qureying seems like the best option. In 99% of cases the contract should be distributed after num_shards blocks"
frol
left a comment
There was a problem hiding this comment.
Please, add support for global contracts deployed by code hash and address the other comment
There was a problem hiding this comment.
Hi! What can be my problem here:
polyprogrammist@Macbooks-MacBook-Pro-2 near-cli-rs % ./target/debug/near
> What are you up to? (select one of the options with the up-down arrows on your
keyboard and press Enter) transaction - Operate transactions
> Сhoose action for transaction: reconstruct-transaction - Use any existing tra
nsaction from the chain to construct NEAR CLI command (helpful tool for re-submi
tting similar transactions)
> Enter the hash of the transaction you want to use as a template: 7iScLbaNApB47
WwMhANr8NnddZaRzmNXHRqd5D2HjAnd
> What is the name of the network? fast
INFO Transaction 7iScLbaNApB47WwMhANr8NnddZaRzmNXHRqd5D2HjAnd:
| signer_id: testglobal.testnet
| receiver_id: testglobal.testnet
| actions: -- deploy code <AgCwqHHwiT2MsmKDeoCvc8K5w6dqsbmpXJZ9yX68kU2i> to a global account <testglobal.testnet>
INFO Trying to fetch contract code for <testglobal.testnet> at block height 220576516 on network <testnet>...
INFO Trying to fetch contract code for <testglobal.testnet> at block height 220576517 on network <testnet>...
INFO Trying to fetch contract code for <testglobal.testnet> at block height 220576518 on network <testnet>...
INFO Trying to fetch contract code for <testglobal.testnet> at block height 220576519 on network <testnet>...
INFO Trying to fetch contract code for <testglobal.testnet> at block height 220576520 on network <testnet>...
INFO Trying to fetch contract code for <testglobal.testnet> at block height 220576521 on network <testnet>...
INFO Trying to fetch contract code for <testglobal.testnet> at block height 220576522 on network <testnet>...
INFO Trying to fetch contract code for <testglobal.testnet> at block height 220576523 on network <testnet>...
INFO Trying to fetch contract code for <testglobal.testnet> at block height 220576524 on network <testnet>...
INFO Trying to fetch contract code for <testglobal.testnet> at block height 220576525 on network <testnet>...
INFO Trying to fetch contract code for <testglobal.testnet> at block height 220576526 on network <testnet>...
INFO Trying to fetch contract code for <testglobal.testnet> at block height 220576527 on network <testnet>...
INFO Trying to fetch contract code for <testglobal.testnet> at block height 220576528 on network <testnet>...
INFO Trying to fetch contract code for <testglobal.testnet> at block height 220576529 on network <testnet>...
INFO Trying to fetch contract code for <testglobal.testnet> at block height 220576530 on network <testnet>...
INFO Trying to fetch contract code for <testglobal.testnet> at block height 220576531 on network <testnet>...
INFO Trying to fetch contract code for <testglobal.testnet> at block height 220576532 on network <testnet>...
INFO Trying to fetch contract code for <testglobal.testnet> at block height 220576533 on network <testnet>...
INFO Trying to fetch contract code for <testglobal.testnet> at block height 220576534 on network <testnet>...
Here is your console command if you need to script it or re-run:
./target/debug/near transaction reconstruct-transaction 7iScLbaNApB47WwMhANr8NnddZaRzmNXHRqd5D2HjAnd network-config fast
Error:
0: Couldn't fetch the code. Please verify that you are using the archival node in the `network_connection.*.rpc_url` field of the `config.toml` file. You can see the list of RPC providers at https://docs.near.org/api/rpc/providers.
Error: Failed to fetch contract code for <testglobal.testnet> on network <testnet> after trying 19 block heights.
Location:
src/commands/transaction/reconstruct_transaction/mod.rs:403
Backtrace omitted. Run with RUST_BACKTRACE=1 environment variable to display it.
Run with RUST_BACKTRACE=full to include source snippets.
polyprogrammist@Macbooks-MacBook-Pro-2 near-cli-rs %
I use the following config:
[network_connection.fast]
network_name = "testnet"
rpc_url = "https://archival-rpc.testnet.fastnear.com/"
wallet_url = "https://archival-rpc.testnet.fastnear.com/"
explorer_transaction_url = "https://archival-rpc.testnet.fastnear.com/"
I have added a simple example for tests in |
|
@frolvanya please take a look at new comments |
|
@race-of-sloths score 11 |
|
@frolvanya Thank you for your contribution! Your pull request is now a part of the Race of Sloths! Current status: executed
Your contribution is much appreciated with a final score of 10! @PolyProgrammist received 25 Sloth Points for reviewing and scoring this pull request. Congratulations @frolvanya! Your PR was highly scored and you completed another monthly streak! To keep your monthly streak make another pull request next month and get 8+ score for it What is the Race of SlothsRace of Sloths is a friendly competition where you can participate in challenges and compete with other open-source contributors within your normal workflow For contributors:
For maintainers:
Feel free to check our website for additional details! Bot commands
|
🏆 Score recorded!It looks like @PolyProgrammist provided a score of 11, but based on our Fibonacci scoring rules, we've adjusted it to 13. Tip We accept only the following Fibonacci numbers [0, 1, 2, 3, 5, 8, 13] for scoring |
|
@frol do you have anything to add here? |
frol
left a comment
There was a problem hiding this comment.
@frolvanya Now it looks good. Thank you for iterating on it!
| .shard_layout | ||
| .num_shards(); | ||
|
|
||
| for block_height in block_height..=block_height + number_of_shards * 2 { |
There was a problem hiding this comment.
@frolvanya The problem with this approach is that if there was already a global contract registerred before, this code will download the outdated contract. One solution I see is to also pass code_hash: Option<CryptoHash> to verify that the downloaded contract actually matches the one in the transaction and keep iterating over the block height until we download the code with the matching hash
| near_primitives::transaction::Action::DeployGlobalContract(deploy) => { | ||
| let code_hash = CryptoHash::hash_bytes(&deploy.code); | ||
| let code_hash = near_primitives::hash::CryptoHash::try_from(deploy.code.as_ref()) | ||
| .expect("The code hash must be valid since it is derived from the code bytes."); |
There was a problem hiding this comment.
Btw, we don't need to take a hash from hash, we just need to convert already hashed bytes into CryptoHash. I didn't check if this issue persists in other places, but probably it's not the only occurrence of this issue
There was a problem hiding this comment.
This is another example of unfortunate naming that got through the time 😢
The original change:
near/nearcore@a295e67#diff-1e4fc99d32e48420a9bd37050fa1412758cba37825851edea40cbdfcab406944L550
The "solidified legacy":
## 🤖 New release
* `near-cli-rs`: 0.22.2 -> 0.23.0 (⚠ API breaking changes)
### ⚠ `near-cli-rs` breaking changes
```text
--- failure auto_trait_impl_removed: auto trait no longer implemented ---
Description:
A public type has stopped implementing one or more auto traits. This can break downstream code that depends on the traits being implemented.
ref: https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits
impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.45.0/src/lints/auto_trait_impl_removed.ron
Failed in:
type DaoProposalArgumentsContext is no longer Send, in /tmp/.tmpJqGcSK/near-cli-rs/src/transaction_signature_options/submit_dao_proposal/mod.rs:86
type DaoProposalArgumentsContext is no longer Sync, in /tmp/.tmpJqGcSK/near-cli-rs/src/transaction_signature_options/submit_dao_proposal/mod.rs:86
type DaoProposalArgumentsContext is no longer UnwindSafe, in /tmp/.tmpJqGcSK/near-cli-rs/src/transaction_signature_options/submit_dao_proposal/mod.rs:86
type DaoProposalArgumentsContext is no longer RefUnwindSafe, in /tmp/.tmpJqGcSK/near-cli-rs/src/transaction_signature_options/submit_dao_proposal/mod.rs:86
type PrepaidGasContext is no longer Send, in /tmp/.tmpJqGcSK/near-cli-rs/src/transaction_signature_options/submit_dao_proposal/mod.rs:141
type PrepaidGasContext is no longer Sync, in /tmp/.tmpJqGcSK/near-cli-rs/src/transaction_signature_options/submit_dao_proposal/mod.rs:141
type PrepaidGasContext is no longer UnwindSafe, in /tmp/.tmpJqGcSK/near-cli-rs/src/transaction_signature_options/submit_dao_proposal/mod.rs:141
type PrepaidGasContext is no longer RefUnwindSafe, in /tmp/.tmpJqGcSK/near-cli-rs/src/transaction_signature_options/submit_dao_proposal/mod.rs:141
type DepositContext is no longer Send, in /tmp/.tmpJqGcSK/near-cli-rs/src/transaction_signature_options/submit_dao_proposal/mod.rs:207
type DepositContext is no longer Sync, in /tmp/.tmpJqGcSK/near-cli-rs/src/transaction_signature_options/submit_dao_proposal/mod.rs:207
type DepositContext is no longer UnwindSafe, in /tmp/.tmpJqGcSK/near-cli-rs/src/transaction_signature_options/submit_dao_proposal/mod.rs:207
type DepositContext is no longer RefUnwindSafe, in /tmp/.tmpJqGcSK/near-cli-rs/src/transaction_signature_options/submit_dao_proposal/mod.rs:207
type DaoProposalContext is no longer Send, in /tmp/.tmpJqGcSK/near-cli-rs/src/transaction_signature_options/submit_dao_proposal/mod.rs:20
type DaoProposalContext is no longer Sync, in /tmp/.tmpJqGcSK/near-cli-rs/src/transaction_signature_options/submit_dao_proposal/mod.rs:20
type DaoProposalContext is no longer UnwindSafe, in /tmp/.tmpJqGcSK/near-cli-rs/src/transaction_signature_options/submit_dao_proposal/mod.rs:20
type DaoProposalContext is no longer RefUnwindSafe, in /tmp/.tmpJqGcSK/near-cli-rs/src/transaction_signature_options/submit_dao_proposal/mod.rs:20
--- failure constructible_struct_adds_field: externally-constructible struct adds field ---
Description:
A pub struct constructible with a struct literal has a new pub field. Existing struct literals must be updated to include the new field.
ref: https://doc.rust-lang.org/reference/expressions/struct-expr.html
impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.45.0/src/lints/constructible_struct_adds_field.ron
Failed in:
field TransactionContext.on_after_signing_callback in /tmp/.tmpJqGcSK/near-cli-rs/src/commands/mod.rs:121
field CliContract.contract_kind in /tmp/.tmpJqGcSK/near-cli-rs/src/commands/contract/download_wasm/mod.rs:299
field NetworkConfig.mpc_contract_account_id in /tmp/.tmpJqGcSK/near-cli-rs/src/config/mod.rs:238
--- failure derive_trait_impl_removed: built-in derived trait no longer implemented ---
Description:
A public type has stopped deriving one or more traits. This can break downstream code that depends on those types implementing those traits.
ref: https://doc.rust-lang.org/reference/attributes/derive.html#derive
impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.45.0/src/lints/derive_trait_impl_removed.ron
Failed in:
type DownloadContractContext no longer derives Clone, in /tmp/.tmpJqGcSK/near-cli-rs/src/commands/contract/download_wasm/mod.rs:86
--- failure enum_missing: pub enum removed or renamed ---
Description:
A publicly-visible enum cannot be imported by its prior path. A `pub use` may have been removed, or the enum itself may have been renamed or removed entirely.
ref: https://doc.rust-lang.org/cargo/reference/semver.html#item-remove
impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.45.0/src/lints/enum_missing.ron
Failed in:
enum near_cli_rs::commands::contract::download_wasm::ClapNamedArgDownloadContractForContract, previously in file /tmp/.tmpsx396w/near-cli-rs/src/commands/contract/download_wasm/mod.rs:8
--- failure enum_no_repr_variant_discriminant_changed: enum variant had its discriminant change value ---
Description:
The enum's variant had its discriminant value change. This breaks downstream code that used its value via a numeric cast like `as isize`.
ref: https://doc.rust-lang.org/reference/items/enumerations.html#assigning-discriminant-values
impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.45.0/src/lints/enum_no_repr_variant_discriminant_changed.ron
Failed in:
variant SignWithDiscriminants::SignLater 6 -> 7 in /tmp/.tmpJqGcSK/near-cli-rs/src/transaction_signature_options/mod.rs:65
variant SignWithDiscriminants::SubmitAsDaoProposal 7 -> 8 in /tmp/.tmpJqGcSK/near-cli-rs/src/transaction_signature_options/mod.rs:70
variant SignWithDiscriminants::SignLater 6 -> 7 in /tmp/.tmpJqGcSK/near-cli-rs/src/transaction_signature_options/mod.rs:65
variant SignWithDiscriminants::SubmitAsDaoProposal 7 -> 8 in /tmp/.tmpJqGcSK/near-cli-rs/src/transaction_signature_options/mod.rs:70
--- failure enum_variant_added: enum variant added on exhaustive enum ---
Description:
A publicly-visible enum without #[non_exhaustive] has a new variant.
ref: https://doc.rust-lang.org/cargo/reference/semver.html#enum-variant-new
impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.45.0/src/lints/enum_variant_added.ron
Failed in:
variant CliSignWith:SignWithMpc in /tmp/.tmpJqGcSK/near-cli-rs/src/transaction_signature_options/mod.rs:20
variant SignWith:SignWithMpc in /tmp/.tmpJqGcSK/near-cli-rs/src/transaction_signature_options/mod.rs:60
variant SignWithDiscriminants:SignWithMpc in /tmp/.tmpJqGcSK/near-cli-rs/src/transaction_signature_options/mod.rs:60
variant SignWithDiscriminants:SignWithMpc in /tmp/.tmpJqGcSK/near-cli-rs/src/transaction_signature_options/mod.rs:60
--- failure inherent_method_missing: pub method removed or renamed ---
Description:
A publicly-visible method or associated fn is no longer available under its prior name. It may have been renamed or removed entirely.
ref: https://doc.rust-lang.org/cargo/reference/semver.html#item-remove
impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.45.0/src/lints/inherent_method_missing.ron
Failed in:
Contract::input_account_id, previously in file /tmp/.tmpsx396w/near-cli-rs/src/commands/contract/download_wasm/mod.rs:39
NearAllowance::from_yoctonear, previously in file /tmp/.tmpsx396w/near-cli-rs/src/types/near_allowance.rs:44
--- failure struct_missing: pub struct removed or renamed ---
Description:
A publicly-visible struct cannot be imported by its prior path. A `pub use` may have been removed, or the struct itself may have been renamed or removed entirely.
ref: https://doc.rust-lang.org/cargo/reference/semver.html#item-remove
impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.45.0/src/lints/struct_missing.ron
Failed in:
struct near_cli_rs::commands::contract::download_wasm::ContractContext, previously in file /tmp/.tmpsx396w/near-cli-rs/src/commands/contract/download_wasm/mod.rs:21
--- failure struct_pub_field_missing: pub struct's pub field removed or renamed ---
Description:
A publicly-visible struct has at least one public field that is no longer available under its prior name. It may have been renamed or removed entirely.
ref: https://doc.rust-lang.org/cargo/reference/semver.html#item-remove
impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.45.0/src/lints/struct_pub_field_missing.ron
Failed in:
field account_id of struct InteractiveClapContextScopeForContract, previously in file /tmp/.tmpsx396w/near-cli-rs/src/commands/contract/download_wasm/mod.rs:8
field account_id of struct CliContract, previously in file /tmp/.tmpsx396w/near-cli-rs/src/commands/contract/download_wasm/mod.rs:8
field save_to_file of struct CliContract, previously in file /tmp/.tmpsx396w/near-cli-rs/src/commands/contract/download_wasm/mod.rs:8
```
<details><summary><i><b>Changelog</b></i></summary><p>
<blockquote>
##
[0.23.0](v0.22.2...v0.23.0)
- 2025-12-11
### Added
- Updated user interface for interactive mode
([#524](#524))
- Added support for reconstructing transaction with global contracts
deploy or use actions
([#521](#521))
- Sign transactions with MPC from a different account or even through a
DAO proposal ([#520](#520))
- Enabled aarch64 Windows binary builds (upgraded cargo-dist to 0.29.0)
([#518](#518))
- introduce tests ([#522](#522))
### Fixed
- Fixed a flaky test (block hash can be 43 or 44 characters long when
base58-encoded) ([#529](#529))
### Other
- bump near-* dependencies to 0.34 (nearcore release 2.10)
([#528](#528))
- changed default rpc to archival fastnear
([#527](#527))
</blockquote>
</p></details>
---
This PR was generated with
[release-plz](https://github.com/release-plz/release-plz/).

Should be merged after:
near/near-jsonrpc-client-rs#179
bos-cli-rs/near-socialdb-client-rs#36