Skip to content

Commit

Permalink
fix: mined tx being invalid (#4735)
Browse files Browse the repository at this point in the history
Description
---
Fix mined transaction marked as invalid in the wallet.
#4721

How Has This Been Tested?
---
I wasn't able to reproduce the original bug. So only github actions tests.
  • Loading branch information
Cifko authored Sep 26, 2022
1 parent 239b64b commit 24e396d
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 9 deletions.
11 changes: 6 additions & 5 deletions applications/tari_base_node/src/grpc/base_node_grpc_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -699,10 +699,10 @@ impl tari_rpc::base_node_server::BaseNode for BaseNodeGrpcServer {
TxStorageResponse::UnconfirmedPool => tari_rpc::SubmitTransactionResponse {
result: tari_rpc::SubmitTransactionResult::Accepted.into(),
},
TxStorageResponse::ReorgPool | TxStorageResponse::NotStoredAlreadySpent => {
tari_rpc::SubmitTransactionResponse {
result: tari_rpc::SubmitTransactionResult::AlreadyMined.into(),
}
TxStorageResponse::ReorgPool |
TxStorageResponse::NotStoredAlreadySpent |
TxStorageResponse::NotStoredAlreadyMined => tari_rpc::SubmitTransactionResponse {
result: tari_rpc::SubmitTransactionResult::AlreadyMined.into(),
},
TxStorageResponse::NotStored |
TxStorageResponse::NotStoredOrphan |
Expand Down Expand Up @@ -778,7 +778,8 @@ impl tari_rpc::base_node_server::BaseNode for BaseNodeGrpcServer {
TxStorageResponse::NotStored |
TxStorageResponse::NotStoredConsensus |
TxStorageResponse::NotStoredOrphan |
TxStorageResponse::NotStoredTimeLocked => tari_rpc::TransactionStateResponse {
TxStorageResponse::NotStoredTimeLocked |
TxStorageResponse::NotStoredAlreadyMined => tari_rpc::TransactionStateResponse {
result: tari_rpc::TransactionLocation::NotStored.into(),
},
};
Expand Down
7 changes: 5 additions & 2 deletions base_layer/core/src/base_node/rpc/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ impl<B: BlockchainBackend + 'static> BaseNodeWalletRpcService<B> {
TxStorageResponse::NotStoredTimeLocked |
TxStorageResponse::NotStoredAlreadySpent |
TxStorageResponse::NotStoredConsensus |
TxStorageResponse::NotStored => TxQueryResponse {
TxStorageResponse::NotStored |
TxStorageResponse::NotStoredAlreadyMined => TxQueryResponse {
location: TxLocation::NotStored as i32,
block_hash: None,
confirmations: 0,
Expand Down Expand Up @@ -207,7 +208,9 @@ impl<B: BlockchainBackend + 'static> BaseNodeWalletService for BaseNodeWalletRpc
rejection_reason: TxSubmissionRejectionReason::ValidationFailed.into(),
is_synced,
},
TxStorageResponse::NotStoredAlreadySpent | TxStorageResponse::ReorgPool => {
TxStorageResponse::NotStoredAlreadySpent |
TxStorageResponse::ReorgPool |
TxStorageResponse::NotStoredAlreadyMined => {
// Is this transaction a double spend or has this transaction been mined?
match transaction.first_kernel_excess_sig() {
None => TxSubmissionResponse {
Expand Down
2 changes: 1 addition & 1 deletion base_layer/core/src/mempool/mempool_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ impl MempoolStorage {
target: LOG_TARGET,
"Validation failed due to already mined kernel: {}", msg
);
TxStorageResponse::NotStoredConsensus
TxStorageResponse::NotStoredAlreadyMined
},
Err(e) => {
warn!(target: LOG_TARGET, "Validation failed due to error: {}", e);
Expand Down
2 changes: 2 additions & 0 deletions base_layer/core/src/mempool/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ pub enum TxStorageResponse {
NotStoredAlreadySpent,
NotStoredConsensus,
NotStored,
NotStoredAlreadyMined,
}

impl TxStorageResponse {
Expand All @@ -129,6 +130,7 @@ impl Display for TxStorageResponse {
TxStorageResponse::NotStoredAlreadySpent => "Not stored output already spent",
TxStorageResponse::NotStoredConsensus => "Not stored due to consensus rule",
TxStorageResponse::NotStored => "Not stored",
TxStorageResponse::NotStoredAlreadyMined => "Not stored tx already mined",
};
fmt.write_str(storage)
}
Expand Down
1 change: 1 addition & 0 deletions base_layer/core/src/mempool/proto/tx_storage_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ impl From<TxStorageResponse> for proto::TxStorageResponse {
NotStoredTimeLocked => proto::TxStorageResponse::NotStored,
NotStoredAlreadySpent => proto::TxStorageResponse::NotStored,
NotStoredConsensus => proto::TxStorageResponse::NotStored,
NotStoredAlreadyMined => proto::TxStorageResponse::NotStored,
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion base_layer/core/tests/mempool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1191,7 +1191,7 @@ async fn consensus_validation_unique_excess_sig() {
let tx = Arc::new(tx1);
let response = mempool.insert(tx).await.unwrap();
dbg!(&response);
assert!(matches!(response, TxStorageResponse::NotStoredConsensus));
assert!(matches!(response, TxStorageResponse::NotStoredAlreadyMined));
}

#[tokio::test]
Expand Down

0 comments on commit 24e396d

Please sign in to comment.