Don't add repeated sent_to entries

This commit is contained in:
Mariano Sorgente 2020-09-15 01:29:44 +09:00 committed by Gene Hoffman
parent a44ac3df5a
commit 4159272684
5 changed files with 30 additions and 21 deletions

View File

@ -244,9 +244,9 @@ export const incomingReducer = (state = { ...initial_state }, action) => {
wallet.name = name; wallet.name = name;
return { ...state }; return { ...state };
} }
if (command === "tx_update") { if (command === "state_changed" && data.state === "tx_update") {
console.log("Got tx update!", data); console.log("Got tx update!", data);
const id = data.id; const id = data.wallet_id;
wallets = state.wallets; wallets = state.wallets;
wallet = wallets[parseInt(id)]; wallet = wallets[parseInt(id)];
wallet.sending_transaction = false; wallet.sending_transaction = false;

View File

@ -194,7 +194,7 @@ class WebSocketServer:
sockets = self.connections[service_name] sockets = self.connections[service_name]
for socket in sockets: for socket in sockets:
try: try:
self.log.info(f"About to ping: {service_name}:{socket}") self.log.info(f"About to ping: {service_name}")
await socket.ping() await socket.ping()
except asyncio.CancelledError: except asyncio.CancelledError:
self.log.info("Ping task received Cancel") self.log.info("Ping task received Cancel")

View File

@ -108,23 +108,25 @@ class TradeStore:
name: str, name: str,
send_status: MempoolInclusionStatus, send_status: MempoolInclusionStatus,
err: Optional[Err], err: Optional[Err],
): ) -> bool:
""" """
Updates trade sent count (Full Node has received spend_bundle and sent ack). Updates trade sent count (Full Node has received spend_bundle and sent ack).
""" """
current: Optional[TradeRecord] = await self.get_trade_record(id) current: Optional[TradeRecord] = await self.get_trade_record(id)
if current is None: if current is None:
return return False
# Don't increment count if it's already sent to othis peer
if name in current.sent_to:
return
sent_to = current.sent_to.copy() sent_to = current.sent_to.copy()
err_str = err.name if err is not None else None err_str = err.name if err is not None else None
sent_to.append((name, uint8(send_status.value), err_str)) append_data = (name, uint8(send_status.value), err_str)
# Don't increment count if it's already sent to othis peer
if append_data in sent_to:
return False
sent_to.append(append_data)
tx: TradeRecord = TradeRecord( tx: TradeRecord = TradeRecord(
confirmed_at_index=current.confirmed_at_index, confirmed_at_index=current.confirmed_at_index,
@ -142,6 +144,7 @@ class TradeStore:
) )
await self.add_trade_record(tx) await self.add_trade_record(tx)
return True
async def set_not_sent(self, id: bytes32): async def set_not_sent(self, id: bytes32):
""" """

View File

@ -702,10 +702,13 @@ class WalletStateManager:
""" """
Full node received our transaction, no need to keep it in queue anymore Full node received our transaction, no need to keep it in queue anymore
""" """
await self.tx_store.increment_sent(spendbundle_id, name, send_status, error) updated = await self.tx_store.increment_sent(
tx: Optional[TransactionRecord] = await self.get_transaction(spendbundle_id) spendbundle_id, name, send_status, error
if tx is not None: )
self.state_changed("tx_update", tx.wallet_id, {"transaction": tx}) if updated:
tx: Optional[TransactionRecord] = await self.get_transaction(spendbundle_id)
if tx is not None:
self.state_changed("tx_update", tx.wallet_id, {"transaction": tx})
async def get_send_queue(self) -> List[TransactionRecord]: async def get_send_queue(self) -> List[TransactionRecord]:
""" """

View File

@ -175,23 +175,25 @@ class WalletTransactionStore:
name: str, name: str,
send_status: MempoolInclusionStatus, send_status: MempoolInclusionStatus,
err: Optional[Err], err: Optional[Err],
): ) -> bool:
""" """
Updates transaction sent count (Full Node has received spend_bundle and sent ack). Updates transaction sent count (Full Node has received spend_bundle and sent ack).
""" """
current: Optional[TransactionRecord] = await self.get_transaction_record(id) current: Optional[TransactionRecord] = await self.get_transaction_record(id)
if current is None: if current is None:
return return False
# Don't increment count if it's already sent to othis peer
if name in current.sent_to:
return
sent_to = current.sent_to.copy() sent_to = current.sent_to.copy()
err_str = err.name if err is not None else None err_str = err.name if err is not None else None
sent_to.append((name, uint8(send_status.value), err_str)) append_data = (name, uint8(send_status.value), err_str)
# Don't increment count if it's already sent to othis peer
if append_data in sent_to:
return False
sent_to.append(append_data)
tx: TransactionRecord = TransactionRecord( tx: TransactionRecord = TransactionRecord(
confirmed_at_index=current.confirmed_at_index, confirmed_at_index=current.confirmed_at_index,
@ -211,6 +213,7 @@ class WalletTransactionStore:
) )
await self.add_transaction_record(tx) await self.add_transaction_record(tx)
return True
async def set_not_sent(self, id: bytes32): async def set_not_sent(self, id: bytes32):
""" """