Skip to content

Commit

Permalink
review 1
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex6323 committed Nov 20, 2023
1 parent 363a153 commit fac3fd2
Show file tree
Hide file tree
Showing 14 changed files with 46 additions and 57 deletions.
12 changes: 6 additions & 6 deletions sdk/src/types/block/core/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
4 changes: 1 addition & 3 deletions sdk/src/types/block/core/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
2 changes: 1 addition & 1 deletion sdk/src/types/block/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions sdk/src/types/block/output/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
8 changes: 4 additions & 4 deletions sdk/src/types/block/output/anchor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
3 changes: 1 addition & 2 deletions sdk/src/types/block/output/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
2 changes: 1 addition & 1 deletion sdk/src/types/block/output/feature/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ impl WorkScore for Features {
Feature::Staking(_) => work_score_params.staking(),
_ => 0,
})
.sum::<u32>()
.sum()
}
}

Expand Down
16 changes: 8 additions & 8 deletions sdk/src/types/block/output/foundry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
6 changes: 3 additions & 3 deletions sdk/src/types/block/output/nft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
19 changes: 8 additions & 11 deletions sdk/src/types/block/payload/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<u8>() 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")
}
}
}
}

Expand Down
7 changes: 3 additions & 4 deletions sdk/src/types/block/payload/signed_transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
9 changes: 4 additions & 5 deletions sdk/src/types/block/payload/signed_transaction/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}

Expand Down
3 changes: 1 addition & 2 deletions sdk/src/types/block/payload/tagged_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}

Expand Down
6 changes: 2 additions & 4 deletions sdk/src/types/block/unlock/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<u32>();
signature_score
.sum()
}
}

Expand Down

0 comments on commit fac3fd2

Please sign in to comment.