Skip to content

Commit

Permalink
Seemingly fix broadcast hanging error.
Browse files Browse the repository at this point in the history
  • Loading branch information
elliedavidson committed Aug 22, 2023
1 parent 183e642 commit 70cb1eb
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 26 deletions.
38 changes: 27 additions & 11 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,29 +324,45 @@ impl<TYPES: NodeType, I: NodeImplementation<TYPES>> SystemContext<TYPES, I> {
};
}

/// Publishes a transaction to the network
/// Publishes a transaction asynchronously to the network
///
/// # Errors
///
/// Will generate an error if an underlying network error occurs
/// Always returns Ok; does not return an error if the transaction couldn't be published to the network
#[instrument(skip(self), err)]
pub async fn publish_transaction_async(
&self,
transaction: TYPES::Transaction,
) -> Result<(), HotShotError<TYPES>> {
// Add the transaction to our own queue first
trace!("Adding transaction to our own queue");
// Wrap up a message
// TODO place a view number here that makes sense
// we haven't worked out how this will work yet
// let message = DataMessage::SubmitTransaction(transaction, TYPES::Time::new(0));

// self.inner.exchanges.committee_exchange().network.broadcast(message).await;

// let api = self.clone();
// async_spawn(async move {
// // let _result = self.inner.exchanges.committee_exchange().network.broadcast(message).await.is_err();
// });
let message = DataMessage::SubmitTransaction(transaction, TYPES::Time::new(0));
let api = self.clone();
// TODO We should have a function that can return a network error if there is one
// but first we'd need to ensure our network implementations can support that
// (and not hang instead)
async_spawn(async move {
let _result = api
.inner
.exchanges
.committee_exchange()
.network()
.broadcast_message(
Message {
sender: api.inner.public_key.clone(),
kind: MessageKind::from(message),
_phantom: PhantomData,
},
&api.inner
.exchanges
.committee_exchange()
.membership()
.clone(),
)
.await;
});
Ok(())
}

Expand Down
4 changes: 0 additions & 4 deletions src/types/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,6 @@ impl<TYPES: NodeType, I: NodeImplementation<TYPES> + 'static> SystemContextHandl
///
/// Will return a [`HotShotError`] if some error occurs in the underlying
/// [`SystemContext`] instance.
///
/// For now this function is deprecated. Use `send_transaction` instead
/// This function will be updated with <https://github.com/EspressoSystems/HotShot/issues/1526>
#[deprecated]
pub async fn submit_transaction(
&self,
tx: TYPES::Transaction,
Expand Down
15 changes: 4 additions & 11 deletions testing/src/txn_task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ impl TxnTaskDescription {
}
Some(node) => {
// use rand::seq::IteratorRandom;
// handle.submit_transaction()
// we're assuming all nodes have the same leaf.
// If they don't match, this is probably fine since
// it should be caught by an assertion (and the txn will be rejected anyway)
Expand All @@ -118,16 +117,10 @@ impl TxnTaskDescription {
&mut thread_rng(),
0,
);
// ED Shouldn't create this each time
let api = HotShotSequencingConsensusApi {
inner: node.handle.hotshot.inner.clone(),
};
api.send_transaction(DataMessage::SubmitTransaction(
txn.clone(),
TYPES::Time::new(0),
))
.await
.expect("Could not send transaction");
node.handle
.submit_transaction(txn.clone())
.await
.expect("Could not send transaction");
(None, state)
}
}
Expand Down

0 comments on commit 70cb1eb

Please sign in to comment.