diff --git a/sdk/src/types/block/core/basic.rs b/sdk/src/types/block/core/basic.rs index 6c0f62f2e9..91abfa1f81 100644 --- a/sdk/src/types/block/core/basic.rs +++ b/sdk/src/types/block/core/basic.rs @@ -156,12 +156,12 @@ impl BasicBlockBody { impl WorkScore for BasicBlockBody { fn work_score(&self, work_score_params: WorkScoreParameters) -> u32 { - let payload_score = self - .payload - .as_ref() - .map(|p| p.work_score(work_score_params)) - .unwrap_or(0); - work_score_params.block() + payload_score + work_score_params.block() + + self + .payload + .as_ref() + .map(|p| p.work_score(work_score_params)) + .unwrap_or(0) } } diff --git a/sdk/src/types/block/core/block.rs b/sdk/src/types/block/core/block.rs index abc251f59c..c0b9244321 100644 --- a/sdk/src/types/block/core/block.rs +++ b/sdk/src/types/block/core/block.rs @@ -292,9 +292,7 @@ impl Block { impl WorkScore for Block { fn work_score(&self, work_score_params: WorkScoreParameters) -> u32 { - let body_score = self.body.work_score(work_score_params); - let signature_score = self.signature.work_score(work_score_params); - body_score + signature_score + self.body.work_score(work_score_params) + self.signature.work_score(work_score_params) } } diff --git a/sdk/src/types/block/core/mod.rs b/sdk/src/types/block/core/mod.rs index 91da3e6ef8..c401d0cf5c 100644 --- a/sdk/src/types/block/core/mod.rs +++ b/sdk/src/types/block/core/mod.rs @@ -107,7 +107,7 @@ impl WorkScore for BlockBody { fn work_score(&self, work_score_params: WorkScoreParameters) -> u32 { match self { Self::Basic(basic) => basic.work_score(work_score_params), - Self::Validation(validation) => 0, + Self::Validation(_) => 0, } } } diff --git a/sdk/src/types/block/output/account.rs b/sdk/src/types/block/output/account.rs index 46aa8b4bf3..29bb19b335 100644 --- a/sdk/src/types/block/output/account.rs +++ b/sdk/src/types/block/output/account.rs @@ -493,9 +493,9 @@ impl StateTransitionVerifier for AccountOutput { impl WorkScore for AccountOutput { fn work_score(&self, work_score_params: WorkScoreParameters) -> u32 { - let features_score = self.features().work_score(work_score_params); - let immutable_features_score = self.immutable_features().work_score(work_score_params); - work_score_params.output() + features_score + immutable_features_score + work_score_params.output() + + self.features().work_score(work_score_params) + + self.immutable_features().work_score(work_score_params) } } diff --git a/sdk/src/types/block/output/anchor.rs b/sdk/src/types/block/output/anchor.rs index e99e66c854..15a607c816 100644 --- a/sdk/src/types/block/output/anchor.rs +++ b/sdk/src/types/block/output/anchor.rs @@ -599,10 +599,10 @@ impl StateTransitionVerifier for AnchorOutput { impl WorkScore for AnchorOutput { fn work_score(&self, work_score_params: WorkScoreParameters) -> u32 { - let native_tokens_score = self.native_tokens().work_score(work_score_params); - let features_score = self.features().work_score(work_score_params); - let immutable_features_score = self.immutable_features().work_score(work_score_params); - work_score_params.output() + native_tokens_score + features_score + immutable_features_score + work_score_params.output() + + self.native_tokens().work_score(work_score_params) + + self.features().work_score(work_score_params) + + self.immutable_features().work_score(work_score_params) } } diff --git a/sdk/src/types/block/output/basic.rs b/sdk/src/types/block/output/basic.rs index 3b21f4e482..3c7a74109a 100644 --- a/sdk/src/types/block/output/basic.rs +++ b/sdk/src/types/block/output/basic.rs @@ -360,8 +360,7 @@ impl BasicOutput { impl WorkScore for BasicOutput { fn work_score(&self, work_score_params: WorkScoreParameters) -> u32 { - let features_score = self.features().work_score(work_score_params); - work_score_params.output() + features_score + work_score_params.output() + self.features().work_score(work_score_params) } } diff --git a/sdk/src/types/block/output/feature/mod.rs b/sdk/src/types/block/output/feature/mod.rs index 67d3c66e17..4a65e603e4 100644 --- a/sdk/src/types/block/output/feature/mod.rs +++ b/sdk/src/types/block/output/feature/mod.rs @@ -266,7 +266,7 @@ impl WorkScore for Features { Feature::Staking(_) => work_score_params.staking(), _ => 0, }) - .sum::() + .sum() } } diff --git a/sdk/src/types/block/output/foundry.rs b/sdk/src/types/block/output/foundry.rs index d260c401df..26bb45867b 100644 --- a/sdk/src/types/block/output/foundry.rs +++ b/sdk/src/types/block/output/foundry.rs @@ -589,14 +589,14 @@ impl StateTransitionVerifier for FoundryOutput { impl WorkScore for FoundryOutput { fn work_score(&self, work_score_params: WorkScoreParameters) -> u32 { - let features_score = self.features().work_score(work_score_params); - let immutable_features_score = self.immutable_features().work_score(work_score_params); - let token_scheme_score = self - .token_scheme() - .is_simple() - .then_some(work_score_params.native_token()) - .unwrap_or(0); - work_score_params.output() + features_score + immutable_features_score + token_scheme_score + work_score_params.output() + + self.features().work_score(work_score_params) + + self.immutable_features().work_score(work_score_params) + + self + .token_scheme() + .is_simple() + .then_some(work_score_params.native_token()) + .unwrap_or(0) } } diff --git a/sdk/src/types/block/output/nft.rs b/sdk/src/types/block/output/nft.rs index 90a8190695..27c665b589 100644 --- a/sdk/src/types/block/output/nft.rs +++ b/sdk/src/types/block/output/nft.rs @@ -489,9 +489,9 @@ impl StateTransitionVerifier for NftOutput { impl WorkScore for NftOutput { fn work_score(&self, work_score_params: WorkScoreParameters) -> u32 { - let features_score = self.features().work_score(work_score_params); - let immutable_features_score = self.immutable_features().work_score(work_score_params); - work_score_params.output() + features_score + immutable_features_score + work_score_params.output() + + self.features().work_score(work_score_params) + + self.immutable_features().work_score(work_score_params) } } diff --git a/sdk/src/types/block/payload/mod.rs b/sdk/src/types/block/payload/mod.rs index a8fcd752a3..012fb402bc 100644 --- a/sdk/src/types/block/payload/mod.rs +++ b/sdk/src/types/block/payload/mod.rs @@ -81,17 +81,14 @@ impl Payload { impl WorkScore for Payload { fn work_score(&self, work_score_params: WorkScoreParameters) -> u32 { // 1 byte for the payload kind - let score = size_of::() as u32 - + match self { - Self::SignedTransaction(signed_transaction_payload) => { - signed_transaction_payload.work_score(work_score_params) - } - Self::TaggedData(tagged_data_payload) => tagged_data_payload.work_score(work_score_params), - Self::CandidacyAnnouncement(candidacy_announcement_payload) => { - todo!("work score for candidacy announcement payload") - } - }; - score + 1 + match self { + Self::SignedTransaction(signed_transaction) => signed_transaction.work_score(work_score_params), + Self::TaggedData(tagged_data) => tagged_data.work_score(work_score_params), + Self::CandidacyAnnouncement(candidacy_announcement) => { + // TODO: Issue #0000 + todo!("work score for candidacy announcement payload") + } + } } } diff --git a/sdk/src/types/block/payload/signed_transaction/mod.rs b/sdk/src/types/block/payload/signed_transaction/mod.rs index 422cce3bea..9b7c65cd0c 100644 --- a/sdk/src/types/block/payload/signed_transaction/mod.rs +++ b/sdk/src/types/block/payload/signed_transaction/mod.rs @@ -50,10 +50,9 @@ impl SignedTransactionPayload { impl WorkScore for SignedTransactionPayload { fn work_score(&self, work_score_params: WorkScoreParameters) -> u32 { - let size_score = self.packed_len() as u32 * work_score_params.data_byte(); - let essence_score = self.transaction().work_score(work_score_params); - let unlocks_score = self.unlocks().work_score(work_score_params); - size_score + essence_score + unlocks_score + self.packed_len() as u32 * work_score_params.data_byte() + + self.transaction().work_score(work_score_params) + + self.unlocks().work_score(work_score_params) } } diff --git a/sdk/src/types/block/payload/signed_transaction/transaction.rs b/sdk/src/types/block/payload/signed_transaction/transaction.rs index ff9d45ba66..914c975fce 100644 --- a/sdk/src/types/block/payload/signed_transaction/transaction.rs +++ b/sdk/src/types/block/payload/signed_transaction/transaction.rs @@ -326,11 +326,10 @@ impl Transaction { impl WorkScore for Transaction { fn work_score(&self, work_score_params: WorkScoreParameters) -> u32 { - let input_score = self.inputs().len() as u32 * work_score_params.input(); - let context_input_score = self.context_inputs().len() as u32 * work_score_params.context_input(); - let outputs_score = self.outputs().work_score(work_score_params); - let allotment_score = self.mana_allotments().len() as u32 * work_score_params.allotment(); - input_score + context_input_score + outputs_score + allotment_score + self.inputs().len() as u32 * work_score_params.input() + + self.context_inputs().len() as u32 * work_score_params.context_input() + + self.outputs().work_score(work_score_params) + + self.mana_allotments().len() as u32 * work_score_params.allotment() } } diff --git a/sdk/src/types/block/payload/tagged_data.rs b/sdk/src/types/block/payload/tagged_data.rs index c46ee9cafb..887eb776b0 100644 --- a/sdk/src/types/block/payload/tagged_data.rs +++ b/sdk/src/types/block/payload/tagged_data.rs @@ -61,8 +61,7 @@ impl TaggedDataPayload { impl WorkScore for TaggedDataPayload { fn work_score(&self, work_score_params: WorkScoreParameters) -> u32 { - let size_score = self.packed_len() as u32 * work_score_params.data_byte(); - size_score + self.packed_len() as u32 * work_score_params.data_byte() } } diff --git a/sdk/src/types/block/unlock/mod.rs b/sdk/src/types/block/unlock/mod.rs index 2f24c3f922..9a8d54fc6f 100644 --- a/sdk/src/types/block/unlock/mod.rs +++ b/sdk/src/types/block/unlock/mod.rs @@ -136,11 +136,9 @@ impl Unlocks { impl WorkScore for Unlocks { fn work_score(&self, work_score_params: WorkScoreParameters) -> u32 { - let signature_score = self - .iter() + self.iter() .filter_map(|u| u.is_signature().then_some(work_score_params.signature_ed25519())) - .sum::(); - signature_score + .sum() } }