Skip to content

Commit

Permalink
limit solution extrinsic to sign phase len
Browse files Browse the repository at this point in the history
  • Loading branch information
niklasad1 committed Dec 13, 2023
1 parent ba427d5 commit ab3593d
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ build:
<<: *collect-artifacts
script:
- cargo build --release --locked
- mv target/release/staking-miner artifacts/
- mv target/release/polkadot-staking-miner artifacts/
- mv Dockerfile artifacts/

### stage: publish
Expand Down
17 changes: 10 additions & 7 deletions src/commands/monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use sp_runtime::Perbill;
use std::{str::FromStr, sync::Arc};
use subxt::{
backend::{legacy::rpc_methods::DryRunResult, rpc::RpcSubscription},
config::Header as _,
config::{DefaultExtrinsicParamsBuilder, Header as _},
error::RpcError,
tx::{TxInBlock, TxProgress},
Error as SubxtError,
Expand Down Expand Up @@ -431,6 +431,7 @@ where
nonce,
config.listen,
config.dry_run,
&at,
)
.timed()
.await
Expand Down Expand Up @@ -523,15 +524,17 @@ async fn submit_and_watch_solution<T: MinerConfig + Send + Sync + 'static>(
nonce: u64,
listen: Listen,
dry_run: bool,
at: &Header,
) -> Result<(), Error> {
let tx = epm::signed_solution(RawSolution { solution, score, round })?;
let signed_phase_len = static_types::SignedPhase::get() as u64;
let ext_cfg = DefaultExtrinsicParamsBuilder::default().mortal(at, signed_phase_len).build();

let xt = client.chain_api().tx().create_signed_with_nonce(
&tx,
&signer,
nonce as u64,
Default::default(),
)?;
let xt =
client
.chain_api()
.tx()
.create_signed_with_nonce(&tx, &signer, nonce as u64, ext_cfg)?;

if dry_run {
let dry_run_bytes = client.rpc().dry_run(xt.encoded(), None).await?;
Expand Down
6 changes: 5 additions & 1 deletion src/epm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,12 +178,13 @@ where
}

/// Read the constants from the metadata and updates the static types.
pub(crate) async fn update_metadata_constants(api: &ChainClient) -> Result<(), Error> {
pub(crate) fn update_metadata_constants(api: &ChainClient) -> Result<(), Error> {
const SIGNED_MAX_WEIGHT: EpmConstant = EpmConstant::new("SignedMaxWeight");
const MAX_LENGTH: EpmConstant = EpmConstant::new("MinerMaxLength");
const MAX_VOTES_PER_VOTER: EpmConstant = EpmConstant::new("MinerMaxVotesPerVoter");
// NOTE: `MaxWinners` is used instead of `MinerMaxWinners` to work with older metadata.
const MAX_WINNERS: EpmConstant = EpmConstant::new("MaxWinners");
const SIGNED_PHASE: EpmConstant = EpmConstant::new("SignedPhase");

fn log_metadata(metadata: EpmConstant, val: impl std::fmt::Display) {
log::trace!(target: LOG_TARGET, "updating metadata constant `{metadata}`: {val}",);
Expand All @@ -193,16 +194,19 @@ pub(crate) async fn update_metadata_constants(api: &ChainClient) -> Result<(), E
let max_length: u32 = read_constant(api, MAX_LENGTH)?;
let max_votes_per_voter: u32 = read_constant(api, MAX_VOTES_PER_VOTER)?;
let max_winners: u32 = read_constant(api, MAX_WINNERS)?;
let sign_phase: u32 = read_constant(api, SIGNED_PHASE)?;

log_metadata(SIGNED_MAX_WEIGHT, max_weight);
log_metadata(MAX_LENGTH, max_length);
log_metadata(MAX_VOTES_PER_VOTER, max_votes_per_voter);
log_metadata(MAX_WINNERS, max_winners);
log_metadata(SIGNED_PHASE, sign_phase);

static_types::MaxWeight::set(max_weight);
static_types::MaxLength::set(max_length);
static_types::MaxVotesPerVoter::set(max_votes_per_voter);
static_types::MaxWinners::set(max_winners);
static_types::SignedPhase::set(sign_phase);

Ok(())
}
Expand Down
6 changes: 3 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,15 +237,15 @@ async fn runtime_upgrade_task(api: ChainClient, tx: oneshot::Sender<Error>) {
let version = update.runtime_version().spec_version;
match updater.apply_update(update) {
Ok(()) => {
if let Err(e) = epm::update_metadata_constants(&api).await {
if let Err(e) = epm::update_metadata_constants(&api) {
let _ = tx.send(e);
return
}
prometheus::on_runtime_upgrade();
log::info!(target: LOG_TARGET, "upgrade to version: {} successful", version);
log::info!(target: LOG_TARGET, "upgrade to v{} successful", version);
},
Err(e) => {
log::debug!(target: LOG_TARGET, "upgrade to version: {} failed: {:?}", version, e);
log::debug!(target: LOG_TARGET, "upgrade to v{} failed: {:?}", version, e);
},
}
}
Expand Down
1 change: 1 addition & 0 deletions src/static_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ mod max_weight {
impl_atomic_u32_parameter_types!(max_length, MaxLength);
impl_atomic_u32_parameter_types!(max_votes, MaxVotesPerVoter);
impl_atomic_u32_parameter_types!(max_winners, MaxWinners);
impl_atomic_u32_parameter_types!(signed_phase, SignedPhase);
pub use max_weight::MaxWeight;

pub mod westend {
Expand Down

0 comments on commit ab3593d

Please sign in to comment.