decrement stored nonce if tx failed for any reason
Signed-off-by: Uncle Stretch <uncle.stretch@ghostchain.io>
This commit is contained in:
		
							parent
							
								
									8f63c7483d
								
							
						
					
					
						commit
						507c03959d
					
				@ -26,6 +26,7 @@ pub use subscriptions::{FinalizedSubscription, BestSubscription};
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
struct TxToWatch {
 | 
					struct TxToWatch {
 | 
				
			||||||
    tx_progress: TxProgress<CasperConfig, OnlineClient<CasperConfig>>,
 | 
					    tx_progress: TxProgress<CasperConfig, OnlineClient<CasperConfig>>,
 | 
				
			||||||
 | 
					    sender: String,
 | 
				
			||||||
    target: ActionTarget,
 | 
					    target: ActionTarget,
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -82,6 +83,13 @@ impl Network {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    fn remove_transaction_and_decrement_nonce(&mut self, index: usize) {
 | 
				
			||||||
 | 
					        let removed = self.transactions_to_watch.remove(index);
 | 
				
			||||||
 | 
					        self.senders
 | 
				
			||||||
 | 
					            .get_mut(&removed.sender)
 | 
				
			||||||
 | 
					            .map(|nonce| *nonce = nonce.saturating_sub(1));
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    pub async fn handle_network_event(&mut self, io_event: Action) -> Result<()> {
 | 
					    pub async fn handle_network_event(&mut self, io_event: Action) -> Result<()> {
 | 
				
			||||||
        match io_event {
 | 
					        match io_event {
 | 
				
			||||||
            Action::NewBestHash(hash) => {
 | 
					            Action::NewBestHash(hash) => {
 | 
				
			||||||
@ -123,21 +131,21 @@ impl Network {
 | 
				
			|||||||
                                }
 | 
					                                }
 | 
				
			||||||
                                TxStatus::Error { message } => {
 | 
					                                TxStatus::Error { message } => {
 | 
				
			||||||
                                    self.action_tx.send(Action::EventLog(format!("transaction {} error, something get wrong: {message}", ext_hash), ActionLevel::Error, log_target))?;
 | 
					                                    self.action_tx.send(Action::EventLog(format!("transaction {} error, something get wrong: {message}", ext_hash), ActionLevel::Error, log_target))?;
 | 
				
			||||||
                                    self.transactions_to_watch.remove(i);
 | 
					                                    self.remove_transaction_and_decrement_nonce(i);
 | 
				
			||||||
                                }
 | 
					                                }
 | 
				
			||||||
                                TxStatus::Invalid { message } => {
 | 
					                                TxStatus::Invalid { message } => {
 | 
				
			||||||
                                    self.action_tx.send(Action::EventLog(format!("transaction {} invalid: {message}", ext_hash), ActionLevel::Error, log_target))?;
 | 
					                                    self.action_tx.send(Action::EventLog(format!("transaction {} invalid: {message}", ext_hash), ActionLevel::Error, log_target))?;
 | 
				
			||||||
                                    self.transactions_to_watch.remove(i);
 | 
					                                    self.remove_transaction_and_decrement_nonce(i);
 | 
				
			||||||
                                }
 | 
					                                }
 | 
				
			||||||
                                TxStatus::Dropped { message } => {
 | 
					                                TxStatus::Dropped { message } => {
 | 
				
			||||||
                                    self.action_tx.send(Action::EventLog(format!("transaction {} was dropped: {message}", ext_hash), ActionLevel::Error, log_target))?;
 | 
					                                    self.action_tx.send(Action::EventLog(format!("transaction {} was dropped: {message}", ext_hash), ActionLevel::Error, log_target))?;
 | 
				
			||||||
                                    self.transactions_to_watch.remove(i);
 | 
					                                    self.remove_transaction_and_decrement_nonce(i);
 | 
				
			||||||
                                }
 | 
					                                }
 | 
				
			||||||
                            }
 | 
					                            }
 | 
				
			||||||
                        },
 | 
					                        },
 | 
				
			||||||
                        _ => {
 | 
					                        _ => {
 | 
				
			||||||
                            self.action_tx.send(Action::EventLog(format!("transaction {} was dropped", ext_hash), ActionLevel::Error, log_target))?;
 | 
					                            self.action_tx.send(Action::EventLog(format!("transaction {} was dropped", ext_hash), ActionLevel::Error, log_target))?;
 | 
				
			||||||
                            self.transactions_to_watch.remove(i);
 | 
					                            self.remove_transaction_and_decrement_nonce(i);
 | 
				
			||||||
                        }
 | 
					                        }
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
@ -212,6 +220,7 @@ impl Network {
 | 
				
			|||||||
                }
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            Action::TransferBalance(sender, receiver, amount) => {
 | 
					            Action::TransferBalance(sender, receiver, amount) => {
 | 
				
			||||||
 | 
					                let sender_cloned = sender.clone();
 | 
				
			||||||
                let maybe_nonce = self.senders.get_mut(&sender);
 | 
					                let maybe_nonce = self.senders.get_mut(&sender);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                let sender: [u8; 32] = hex::decode(sender)
 | 
					                let sender: [u8; 32] = hex::decode(sender)
 | 
				
			||||||
@ -230,6 +239,7 @@ impl Network {
 | 
				
			|||||||
                ).await {
 | 
					                ).await {
 | 
				
			||||||
                    self.transactions_to_watch.push(TxToWatch {
 | 
					                    self.transactions_to_watch.push(TxToWatch {
 | 
				
			||||||
                        tx_progress,
 | 
					                        tx_progress,
 | 
				
			||||||
 | 
					                        sender: sender_cloned,
 | 
				
			||||||
                        target: ActionTarget::WalletLog,
 | 
					                        target: ActionTarget::WalletLog,
 | 
				
			||||||
                    });
 | 
					                    });
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user