Skip to content

Commit

Permalink
fix(wallet): add missing resource_id field in upsert (#1309)
Browse files Browse the repository at this point in the history
Description
---
fix(wallet): add missing resource_id field in upsert

Motivation and Context
---
Missing NOT NULL field in insert
  • Loading branch information
sdbondi authored Feb 25, 2025
1 parent 9f882b0 commit 737599c
Show file tree
Hide file tree
Showing 23 changed files with 52 additions and 90 deletions.
10 changes: 6 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ concurrency:
cancel-in-progress: ${{ !startsWith(github.ref, 'refs/tags/v') || github.ref != 'refs/heads/development' }}

env:
nightly_toolchain: nightly-2025-01-17
stable_toolchain: 1.84
nightly_toolchain: nightly-2025-02-25
stable_toolchain: stable
CARGO_HTTP_MULTIPLEXING: false
CARGO_TERM_COLOR: always
TARI_TARGET_NETWORK: localnet
TARI_NETWORK: localnet
# https://github.com/rust-lang/rustup/issues/2949#issuecomment-2584968659
RUSTUP_PERMIT_COPY_RENAME: true
PROTOC: protoc
TERM: unknown

Expand Down Expand Up @@ -148,10 +150,10 @@ jobs:
- uses: rui314/setup-mold@v1

- name: wasm target install
run: rustup target add wasm32-unknown-unknown
run: rustup +${{ env.nightly_toolchain }} target add wasm32-unknown-unknown

- name: cargo check
run: cargo check --release --all-features --all-targets --locked
run: cargo +${{ env.nightly_toolchain }} check --release --all-features --all-targets --locked

build-stable:
name: check stable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@ async fn finish_claiming<T: WalletStore>(
if new_account_name.is_none() {
// Add all versioned account child addresses as inputs unless the account is new
let child_addresses = sdk.substate_api().load_dependent_substates(&[&account_address])?;
inputs.extend(child_addresses.into_iter().map(Into::into));
inputs.extend(child_addresses);
instructions.push(Instruction::CallMethod {
component_address: account_component_address,
method: "deposit".to_string(),
Expand Down
4 changes: 2 additions & 2 deletions applications/tari_indexer/src/event_scanner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,11 +237,11 @@ impl EventScanner {
}

fn event_matches_filter(filter: &EventFilter, event: &Event) -> bool {
let matches_topic = filter.topic.as_ref().map_or(true, |t| *t == event.topic());
let matches_topic = filter.topic.as_ref().is_none_or(|t| *t == event.topic());
let matches_template = filter
.template_address
.as_ref()
.map_or(true, |t| *t == event.template_address());
.is_none_or(|t| *t == event.template_address());

let matches_substate_id = match filter.substate_id {
Some(ref substate_id) => event.substate_id().map(|s| s == substate_id).unwrap_or(false),
Expand Down
4 changes: 1 addition & 3 deletions applications/tari_swarm_daemon/src/webserver/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,7 @@ async fn handler(
) -> impl IntoResponse {
if let Some(ref basic_auth) = context.config().webserver.base_auth {
// NOTE: this does not have to be secure (timing attacks etc), this is to prevent easy access to the Web UI
if auth.map_or(true, |a| {
a.username() != basic_auth.username || a.password() != basic_auth.password
}) {
if auth.is_none_or(|a| a.username() != basic_auth.username || a.password() != basic_auth.password) {
return Response::builder()
.status(StatusCode::UNAUTHORIZED)
.header("WWW-Authenticate", "Basic realm=\"tari-swarm\"")
Expand Down
2 changes: 1 addition & 1 deletion applications/tari_watcher/src/transaction_worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ async fn check_and_submit_layer_one_transactions(
trace!("Skipping non-file: {}", file.path().display());
continue;
}
if file.path().extension().map_or(true, |s| s != "json") {
if file.path().extension().is_none_or(|s| s != "json") {
debug!("Skipping non-JSON file: {}", file.path().display());
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ pub fn process_foreign_block<TStore: StateStore>(
// aborted later.
match conflicting_evidence.inputs().get(id) {
Some(Some(ev)) => {
let conflicting_is_write = e.as_ref().map_or(true, |e| e.is_write);
let conflicting_is_write = e.as_ref().is_none_or(|e| e.is_write);
// If either are write, we ABORT
conflicting_is_write || ev.is_write
},
Expand Down
3 changes: 1 addition & 2 deletions dan_layer/epoch_manager/src/service/epoch_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,8 +346,7 @@ where TSpec: EpochManagerSpec
epoch: Epoch,
) -> Result<Vec<ValidatorNode<TSpec::Addr>>, EpochManagerError> {
let mut tx = self.global_db.create_transaction()?;
let db_vns = self.global_db.validator_nodes(&mut tx).get_all_within_epoch(epoch)?;
let vns = db_vns.into_iter().map(Into::into).collect();
let vns = self.global_db.validator_nodes(&mut tx).get_all_within_epoch(epoch)?;
Ok(vns)
}

Expand Down
2 changes: 1 addition & 1 deletion dan_layer/indexer_lib/src/substate_scanner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ where
let substate_result = self.get_substate_from_committee_by_requirement(&requirement).await?;
debug!(target: LOG_TARGET, "Substate result for {} with version {}: {:?}", substate_id.to_address_string(), specific_version.display(), substate_result);
if let Some(version) = substate_result.version() {
let should_update_cache = cached_version.map_or(true, |v| v < version);
let should_update_cache = cached_version.is_none_or(|v| v < version);
if should_update_cache {
debug!(target: LOG_TARGET, "Updating cached substate {} with version {}", substate_id.to_address_string(), version);
let entry = SubstateCacheEntry {
Expand Down
2 changes: 1 addition & 1 deletion dan_layer/state_store_sqlite/src/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1528,7 +1528,7 @@ impl<'tx, TAddr: NodeAddressable + 'tx> StateStoreWriteTransaction for SqliteSta

let mut remaining = counts
.iter()
.filter(|(_, count)| count.map_or(true, |c| c == 0))
.filter(|(_, count)| count.is_none_or(|c| c == 0))
.map(|(id, _)| *id)
.peekable();

Expand Down
5 changes: 2 additions & 3 deletions dan_layer/storage/src/consensus_models/block_pledges.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ impl BlockPledge {
if let Some((id, ev)) = evidence.all_pledged_inputs_iter().find(|(substate_id, ev)| {
self.pledges
.get(substate_id)
.map_or(true, |value| value.version() != ev.version)
.is_none_or(|value| value.version() != ev.version)
}) {
warn!(
target: LOG_TARGET,
Expand Down Expand Up @@ -182,8 +182,7 @@ impl SubstatePledge {
let req = req.into();
// Check if a requirement is met by this pledge. If the requirement does not specify a version, then the version
// requirement is, by definition, met.
req.version
.map_or(true, |v| v == self.versioned_substate_id().version()) &&
req.version.is_none_or(|v| v == self.versioned_substate_id().version()) &&
self.substate_id() == req.substate_id()
}

Expand Down
4 changes: 2 additions & 2 deletions dan_layer/storage/src/consensus_models/evidence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,11 @@ impl Evidence {
/// This assumes the provided evidence is complete before this is called.
/// If no evidence is present for the shard group, false is returned.
pub fn is_committee_output_only(&self, shard_group: ShardGroup) -> bool {
self.evidence.get(&shard_group).map_or(true, |e| e.inputs().is_empty())
self.evidence.get(&shard_group).is_none_or(|e| e.inputs().is_empty())
}

pub fn is_committee_input_only(&self, shard_group: ShardGroup) -> bool {
self.evidence.get(&shard_group).map_or(true, |e| e.outputs().is_empty())
self.evidence.get(&shard_group).is_none_or(|e| e.outputs().is_empty())
}

pub fn is_empty(&self) -> bool {
Expand Down
2 changes: 1 addition & 1 deletion dan_layer/storage/src/consensus_models/substate_lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ impl LockedSubstateValue {

pub fn satisfies_requirements<'a, T: Into<SubstateRequirementRef<'a>>>(&self, requirement: T) -> bool {
let requirement = requirement.into();
requirement.version().map_or(true, |v| v == self.lock.version) && *requirement.substate_id() == self.substate_id
requirement.version().is_none_or(|v| v == self.lock.version) && *requirement.substate_id() == self.substate_id
}

pub fn satisfies_lock_intent<T: LockIntent>(&self, lock_intent: T) -> bool {
Expand Down
2 changes: 1 addition & 1 deletion dan_layer/storage/src/consensus_models/transaction_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ impl TransactionPoolRecord {
execution: &TransactionExecution,
) -> &mut Self {
// Only change the local decision if we haven't already decided to ABORT
if self.local_decision().map_or(true, |d| d.is_commit()) {
if self.local_decision().is_none_or(|d| d.is_commit()) {
self.set_local_decision(execution.decision());
}

Expand Down
20 changes: 7 additions & 13 deletions dan_layer/storage/src/global/base_layer_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,28 +39,22 @@ impl<'a, 'tx, TGlobalDbAdapter: GlobalDbAdapter> BaseLayerDb<'a, 'tx, TGlobalDbA
}

pub fn insert_base_layer_block_info(&mut self, info: DbBaseLayerBlockInfo) -> Result<(), TGlobalDbAdapter::Error> {
self.backend
.insert_base_layer_block_info(self.tx, info)
.map_err(TGlobalDbAdapter::Error::into)
self.backend.insert_base_layer_block_info(self.tx, info)
}

pub fn get_base_layer_block_height(
&mut self,
hash: FixedHash,
) -> Result<Option<DbBaseLayerBlockInfo>, TGlobalDbAdapter::Error> {
self.backend
.get_base_layer_block_info(self.tx, hash)
.map_err(TGlobalDbAdapter::Error::into)
self.backend.get_base_layer_block_info(self.tx, hash)
}

pub fn insert_eviction_proof(&mut self, proof: &EvictionProof) -> Result<(), TGlobalDbAdapter::Error> {
self.backend
.insert_layer_one_transaction(self.tx, DbLayer1Transaction {
epoch: Epoch(proof.epoch().as_u64()),
proof_type: DbLayerOnePayloadType::EvictionProof,
payload: proof,
})
.map_err(TGlobalDbAdapter::Error::into)
self.backend.insert_layer_one_transaction(self.tx, DbLayer1Transaction {
epoch: Epoch(proof.epoch().as_u64()),
proof_type: DbLayerOnePayloadType::EvictionProof,
payload: proof,
})
}
}

Expand Down
8 changes: 2 additions & 6 deletions dan_layer/storage/src/global/bmt_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,14 @@ impl<'a, 'tx, TGlobalDbAdapter: GlobalDbAdapter> BmtDb<'a, 'tx, TGlobalDbAdapter
epoch: u64,
bmt: ValidatorNodeBalancedMerkleTree,
) -> Result<(), TGlobalDbAdapter::Error> {
self.backend
.insert_bmt(self.tx, epoch, bmt)
.map_err(TGlobalDbAdapter::Error::into)
self.backend.insert_bmt(self.tx, epoch, bmt)
}

pub fn get_bmt(
&mut self,
epoch: Epoch,
) -> Result<Option<ValidatorNodeBalancedMerkleTree>, TGlobalDbAdapter::Error> {
self.backend
.get_bmt(self.tx, epoch)
.map_err(TGlobalDbAdapter::Error::into)
self.backend.get_bmt(self.tx, epoch)
}
}

Expand Down
8 changes: 2 additions & 6 deletions dan_layer/storage/src/global/epoch_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,11 @@ impl<'a, 'tx, TGlobalDbAdapter: GlobalDbAdapter> EpochDb<'a, 'tx, TGlobalDbAdapt
}

pub fn insert_epoch(&mut self, db_epoch: DbEpoch) -> Result<(), TGlobalDbAdapter::Error> {
self.backend
.insert_epoch(self.tx, db_epoch)
.map_err(TGlobalDbAdapter::Error::into)
self.backend.insert_epoch(self.tx, db_epoch)
}

pub fn get_epoch_data(&mut self, epoch: u64) -> Result<Option<DbEpoch>, TGlobalDbAdapter::Error> {
self.backend
.get_epoch(self.tx, epoch)
.map_err(TGlobalDbAdapter::Error::into)
self.backend.get_epoch(self.tx, epoch)
}
}

Expand Down
45 changes: 13 additions & 32 deletions dan_layer/storage/src/global/validator_node_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,14 @@ impl<'a, 'tx, TGlobalDbAdapter: GlobalDbAdapter> ValidatorNodeDb<'a, 'tx, TGloba
start_epoch: Epoch,
fee_claim_public_key: PublicKey,
) -> Result<(), TGlobalDbAdapter::Error> {
self.backend
.insert_validator_node(
self.tx,
peer_address,
public_key,
shard_key,
start_epoch,
fee_claim_public_key,
)
.map_err(TGlobalDbAdapter::Error::into)
self.backend.insert_validator_node(
self.tx,
peer_address,
public_key,
shard_key,
start_epoch,
fee_claim_public_key,
)
}

pub fn deactivate(
Expand All @@ -64,13 +62,10 @@ impl<'a, 'tx, TGlobalDbAdapter: GlobalDbAdapter> ValidatorNodeDb<'a, 'tx, TGloba
) -> Result<(), TGlobalDbAdapter::Error> {
self.backend
.deactivate_validator_node(self.tx, public_key, deactivation_epoch)
.map_err(TGlobalDbAdapter::Error::into)
}

pub fn count(&mut self, epoch: Epoch) -> Result<u64, TGlobalDbAdapter::Error> {
self.backend
.validator_nodes_count(self.tx, epoch)
.map_err(TGlobalDbAdapter::Error::into)
self.backend.validator_nodes_count(self.tx, epoch)
}

pub fn count_in_shard_group(
Expand All @@ -80,7 +75,6 @@ impl<'a, 'tx, TGlobalDbAdapter: GlobalDbAdapter> ValidatorNodeDb<'a, 'tx, TGloba
) -> Result<u64, TGlobalDbAdapter::Error> {
self.backend
.validator_nodes_count_for_shard_group(self.tx, epoch, shard_group)
.map_err(TGlobalDbAdapter::Error::into)
}

pub fn get_by_public_key(
Expand All @@ -90,17 +84,14 @@ impl<'a, 'tx, TGlobalDbAdapter: GlobalDbAdapter> ValidatorNodeDb<'a, 'tx, TGloba
) -> Result<ValidatorNode<TGlobalDbAdapter::Addr>, TGlobalDbAdapter::Error> {
self.backend
.get_validator_node_by_public_key(self.tx, epoch, public_key)
.map_err(TGlobalDbAdapter::Error::into)
}

pub fn get_by_address(
&mut self,
epoch: Epoch,
address: &TGlobalDbAdapter::Addr,
) -> Result<ValidatorNode<TGlobalDbAdapter::Addr>, TGlobalDbAdapter::Error> {
self.backend
.get_validator_node_by_address(self.tx, epoch, address)
.map_err(TGlobalDbAdapter::Error::into)
self.backend.get_validator_node_by_address(self.tx, epoch, address)
}

/// Returns all registered validator nodes from the given epoch
Expand All @@ -111,19 +102,15 @@ impl<'a, 'tx, TGlobalDbAdapter: GlobalDbAdapter> ValidatorNodeDb<'a, 'tx, TGloba
&mut self,
epoch: Epoch,
) -> Result<Vec<ValidatorNode<TGlobalDbAdapter::Addr>>, TGlobalDbAdapter::Error> {
self.backend
.get_validator_nodes_within_start_epoch(self.tx, epoch)
.map_err(TGlobalDbAdapter::Error::into)
self.backend.get_validator_nodes_within_start_epoch(self.tx, epoch)
}

/// Fetches all validator nodes that are active for a given epoch
pub fn get_all_within_epoch(
&mut self,
epoch: Epoch,
) -> Result<Vec<ValidatorNode<TGlobalDbAdapter::Addr>>, TGlobalDbAdapter::Error> {
self.backend
.get_validator_nodes_within_committee_epoch(self.tx, epoch)
.map_err(TGlobalDbAdapter::Error::into)
self.backend.get_validator_nodes_within_committee_epoch(self.tx, epoch)
}

pub fn get_committee_for_shard_group(
Expand All @@ -135,7 +122,6 @@ impl<'a, 'tx, TGlobalDbAdapter: GlobalDbAdapter> ValidatorNodeDb<'a, 'tx, TGloba
) -> Result<Committee<TGlobalDbAdapter::Addr>, TGlobalDbAdapter::Error> {
self.backend
.validator_nodes_get_for_shard_group(self.tx, epoch, shard_group, shuffle, limit)
.map_err(TGlobalDbAdapter::Error::into)
}

pub fn get_committees_overlapping_shard_group(
Expand All @@ -145,7 +131,6 @@ impl<'a, 'tx, TGlobalDbAdapter: GlobalDbAdapter> ValidatorNodeDb<'a, 'tx, TGloba
) -> Result<HashMap<ShardGroup, Committee<TGlobalDbAdapter::Addr>>, TGlobalDbAdapter::Error> {
self.backend
.validator_nodes_get_overlapping_shard_group(self.tx, epoch, shard_group)
.map_err(TGlobalDbAdapter::Error::into)
}

pub fn get_random_committee_member_from_shard_group(
Expand All @@ -156,16 +141,13 @@ impl<'a, 'tx, TGlobalDbAdapter: GlobalDbAdapter> ValidatorNodeDb<'a, 'tx, TGloba
) -> Result<ValidatorNode<TGlobalDbAdapter::Addr>, TGlobalDbAdapter::Error> {
self.backend
.validator_nodes_get_random_committee_member_from_shard_group(self.tx, epoch, shard_group, excluding)
.map_err(TGlobalDbAdapter::Error::into)
}

pub fn get_committees(
&mut self,
epoch: Epoch,
) -> Result<HashMap<ShardGroup, Committee<TGlobalDbAdapter::Addr>>, TGlobalDbAdapter::Error> {
self.backend
.validator_nodes_get_committees_for_epoch(self.tx, epoch)
.map_err(TGlobalDbAdapter::Error::into)
self.backend.validator_nodes_get_committees_for_epoch(self.tx, epoch)
}

pub fn set_committee_shard(
Expand All @@ -176,6 +158,5 @@ impl<'a, 'tx, TGlobalDbAdapter: GlobalDbAdapter> ValidatorNodeDb<'a, 'tx, TGloba
) -> Result<(), TGlobalDbAdapter::Error> {
self.backend
.validator_nodes_set_committee_shard(self.tx, substate_address, shard_group, epoch)
.map_err(TGlobalDbAdapter::Error::into)
}
}
5 changes: 1 addition & 4 deletions dan_layer/template_lib/src/models/non_fungible.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,10 +261,7 @@ impl NonFungibleAddress {
return None;
}
match self.id() {
NonFungibleId::U256(bytes) => match RistrettoPublicKeyBytes::from_bytes(bytes) {
Ok(public_key) => Some(public_key),
Err(_) => None,
},
NonFungibleId::U256(bytes) => RistrettoPublicKeyBytes::from_bytes(bytes).ok(),
_ => None,
}
}
Expand Down
2 changes: 1 addition & 1 deletion dan_layer/wallet/storage_sqlite/src/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -907,6 +907,7 @@ impl WalletStoreWriter for WriteTransaction<'_> {
.values((
non_fungible_tokens::nft_id.eq(non_fungible_token.nft_id.to_canonical_string()),
non_fungible_tokens::data.eq(&data),
non_fungible_tokens::resource_id.eq(non_fungible_token.resource_address.to_string()),
non_fungible_tokens::mutable_data.eq(&mutable_data),
non_fungible_tokens::vault_id.eq(vault_id),
non_fungible_tokens::is_burned.eq(non_fungible_token.is_burned),
Expand All @@ -916,7 +917,6 @@ impl WalletStoreWriter for WriteTransaction<'_> {
.set((
non_fungible_tokens::data.eq(&data),
non_fungible_tokens::mutable_data.eq(&mutable_data),
non_fungible_tokens::vault_id.eq(vault_id),
non_fungible_tokens::is_burned.eq(non_fungible_token.is_burned),
))
.execute(self.connection())
Expand Down
Loading

0 comments on commit 737599c

Please sign in to comment.