Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: potential panics when calling into contract #629

Merged
merged 2 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions chain-signatures/Cargo.lock

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

2 changes: 1 addition & 1 deletion chain-signatures/node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ url = { version = "2.4.0", features = ["serde"] }

near-account-id = "1.0.0"
near-crypto = "0.21.2"
near-fetch = { git = "https://github.com/ChaoticTempest/fetch.git" }
near-fetch = "0.3.1"
near-lake-framework = { git = "https://github.com/near/near-lake-framework-rs", branch = "dmd/bump-dependencies" }
near-lake-primitives = { git = "https://github.com/near/near-lake-framework-rs", branch = "dmd/bump-dependencies" }
near-primitives = "0.21.2"
Expand Down
8 changes: 4 additions & 4 deletions chain-signatures/node/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,12 +236,12 @@ pub fn run(cmd: Cli) -> anyhow::Result<()> {
let signer = InMemorySigner::from_secret_key(account_id.clone(), account_sk);
let (protocol, protocol_state) = MpcSignProtocol::init(
my_address,
mpc_contract_id.clone(),
mpc_contract_id,
account_id,
rpc_client.clone(),
signer.clone(),
rpc_client,
signer,
receiver,
sign_queue.clone(),
sign_queue,
key_storage,
triple_storage,
Config {
Expand Down
21 changes: 19 additions & 2 deletions chain-signatures/node/src/protocol/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ pub enum ConsensusError {
HasBeenKicked,
#[error("this node errored out during the join process: {0}")]
CannotJoin(String),
#[error("this node errored out while trying to vote: {0}")]
CannotVote(String),
#[error("cait-sith initialization error: {0}")]
CaitSithInitializationError(#[from] InitializationError),
#[error("secret storage error: {0}")]
Expand Down Expand Up @@ -314,7 +316,14 @@ impl ConsensusProtocol for WaitingForConsensusState {
&public_key,
)
.await
.unwrap();
.map_err(|err| {
tracing::error!(
?public_key,
?err,
"failed to vote for the generated public key"
);
ConsensusError::CannotVote(format!("{err:?}"))
})?;
}
Ok(NodeState::WaitingForConsensus(self))
}
Expand Down Expand Up @@ -433,7 +442,14 @@ impl ConsensusProtocol for WaitingForConsensusState {
self.epoch,
)
.await
.unwrap();
.map_err(|err| {
tracing::error!(
epoch = self.epoch,
?err,
"failed to vote for resharing"
);
ConsensusError::CannotVote(format!("{err:?}"))
})?;
} else {
tracing::info!(
epoch = self.epoch,
Expand Down Expand Up @@ -649,6 +665,7 @@ impl ConsensusProtocol for JoiningState {
"sign_pk": ctx.cfg().network_cfg.sign_sk.public_key(),
}))
.max_gas()
.retry_exponential(10, 3)
.transact()
.await
.map_err(|err| {
Expand Down
2 changes: 1 addition & 1 deletion chain-signatures/node/src/protocol/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use crate::mesh::{Mesh, NetworkConfig};
use crate::protocol::consensus::ConsensusProtocol;
use crate::protocol::cryptography::CryptographicProtocol;
use crate::protocol::message::{MessageHandler, MpcMessageQueue};
use crate::rpc_client::{self};
use crate::rpc_client;
use crate::storage::secret_storage::SecretNodeStorageBox;
use crate::storage::triple_storage::LockTripleNodeStorageBox;

Expand Down
1 change: 1 addition & 0 deletions chain-signatures/node/src/protocol/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,7 @@ impl SignatureManager {
"response": signature,
}))
.max_gas()
.retry_exponential(10, 5)
.transact()
.await?;
crate::metrics::NUM_SIGN_SUCCESS
Expand Down
17 changes: 6 additions & 11 deletions chain-signatures/node/src/rpc_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use crate::protocol::ProtocolState;

use near_account_id::AccountId;
use near_crypto::InMemorySigner;
use near_primitives::views::FinalExecutionStatus;

use serde_json::json;

Expand Down Expand Up @@ -32,12 +31,10 @@ pub async fn vote_for_public_key(
.max_gas()
.retry_exponential(10, 5)
.transact()
.await?;
.await?
.json()?;

match result.status() {
FinalExecutionStatus::SuccessValue(value) => Ok(serde_json::from_slice(value)?),
status => anyhow::bail!("unexpected status: {:?}", status),
}
Ok(result)
}

pub async fn vote_reshared(
Expand All @@ -54,10 +51,8 @@ pub async fn vote_reshared(
.max_gas()
.retry_exponential(10, 5)
.transact()
.await?;
.await?
.json()?;

match result.status() {
FinalExecutionStatus::SuccessValue(value) => Ok(serde_json::from_slice(value)?),
status => anyhow::bail!("unexpected status: {:?}", status),
}
Ok(result)
}
5 changes: 3 additions & 2 deletions integration-tests/chain-signatures/Cargo.lock

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

2 changes: 1 addition & 1 deletion integration-tests/chain-signatures/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ k256 = { version = "0.13.1", features = ["sha256", "ecdsa", "serde"] }
# near dependencies
near-account-id = "1"
near-crypto = "0.21"
near-fetch = { git = "https://github.com/ChaoticTempest/fetch.git" }
near-fetch = "0.3.1"
near-jsonrpc-client = "0.9"
near-primitives = "0.21"
near-lake-framework = { git = "https://github.com/near/near-lake-framework-rs", branch = "dmd/bump-dependencies" }
Expand Down
4 changes: 1 addition & 3 deletions integration-tests/chain-signatures/tests/actions/wait_for.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,7 @@ pub async fn signature_responded(
wait_until: near_primitives::views::TxExecutionStatus::Final,
})
.await?;
// let FinalExecutionStatus::SuccessValue(payload) = outcome_view.status else {
// anyhow::bail!("tx finished unsuccessfully: {:?}", outcome_view.status);
// };

let Some(outcome) = outcome_view.final_execution_outcome else {
anyhow::bail!("final execution outcome not available");
};
Expand Down
Loading