-
Notifications
You must be signed in to change notification settings - Fork 34
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As mentioned in the related issue discussion, this looks OK -- I'd wait for comments from @ebuchman @melekes @liamsi.
I'd only request two changes:
-
integrate / add tests -- the previous code worked over "AbciStream" and the point was that this could abstract over the underlying connection -- a mock connection in tests, TCP or UDS in application code.
-
remove the
Copy
trait requirement on ABCI app.
That will have some implications later in the code that could be resolved in different ways:
- bring the
Arc<Mutex<...>>
back for the moment (if the latter incurs big changes) - shuffle the execution pipeline to be something like this:
(thread pool for async reading/parsing of ABCI requests from different connections)
=>
(a dedicated single thread owning ABCI app for generating ABCI responses)
=>
(thread pool for async writing of ABCI responses to corresponding connections)
src/lib.rs
Outdated
@@ -101,7 +105,7 @@ pub trait Application { | |||
/// Setup the app and start the server using localhost and default tendermint port 26658 | |||
pub fn run_local<A>(app: A) | |||
where | |||
A: Application + 'static + Send + Sync, | |||
A: Application + 'static + Send + Sync + Copy, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this will potentially break client code -- not all ABCI applications will implement "Copy", e.g. one of fields could be a DB connection.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, @tomtau I have removed "Copy" from the latest version, please check.
src/server.rs
Outdated
|
||
// Wrap the app atomically and clone for each connection. | ||
let app = Arc::new(Mutex::new(app)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if this can be removed (and Copy
can't really be required, as mentioned in https://github.com/tendermint/rust-abci/pull/50/files#diff-b4aea3e418ccdb71239b96952d9cddb6R108 ) . When I mentioned in #31 (comment) that there may not be a reason for mutex, I meant the following possibilities:
- if the request reading / parsing is separate from response generation, the response generation could potentially be in one system thread, so no need for app synchronisation / locking... the app could then say be wrapped say in
Rc<Cell<...>>
or owned within that "response generating" thread's scope - if the
Application
trait is changed, such that it doesn't require a mutable ref in Mempool/Info connection-related operations (CheckTx, Query...), there could be aRwLock
instead ofMutex
... this could be good, but could also lead to some problems, e.g. a writer starvation. - if the
Application
trait is split into some sort of "Query" and "Update" parts and it's somehow possible to distinguish among those 3 ABCI connections, it may be possible to use them without dynamic wrapping -- Mempool and Info connections would get "&ApplicationQuery", Consensus connection would get "&mut ApplicationUpdate".
Perhaps the first possibility can be easily applied here, but if not, I'd leave it for now and open a separate issue for this, because it requires a significant re-architecting of rust-abci.
@davebryson any thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks ok for start. Just one missing bit is basic tests -- before it operated over this stream: https://github.com/tendermint/rust-abci/blob/master/src/stream.rs#L12 So perhaps that could be somehow modified to use Tokio stuff?
src/lib.rs
Outdated
@@ -10,6 +10,7 @@ | |||
//! the Trait. The app doesn't do any actual processing on a transaction. | |||
//! | |||
//! ```rust,no_run | |||
//! #[derive(Clone, Copy)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't be needed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Resolved in the version
f3f4653
src/codec/abci.rs
Outdated
buf.put(&varint); | ||
buf.reserve(1 + msg_len as usize); | ||
msg.write_to_writer(&mut buf.writer()).unwrap(); | ||
println!("Encode response! {:?}", &buf[..]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
merge with the latest master and use e.g. info!
logger call instead
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Resolved in the version
eecdf56
hmm... in my opinion, ABCI protocol is based on TcpStream, we do not need to mock TcpStream, so I think maybe it will better to remove the stream.rs file, but we need to add some test for ABCI codec, it only has a relationship with data codec but not stream if we do need to add some mock TcpStream, maybe it will be better to add some test to server.rs, since that it has some relationship with the data stream |
Well, ABCI can run over TCP or Unix Domain sockets -- see #47 so ideally encoding/decoding is abstracted from that |
2.refactoring abci.rs and add error handling
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@enginespot the latest changes look good -- I think removing ABCIStream
make sense; the use of ABCICode
should have the similar benefits (for testing and later extending it to run over Unix Domain Sockets instead of TCP).
The remaining change is that it seems this PR accidentally reverted the changes from this PR: https://github.com/tendermint/rust-abci/pull/48/files which would break the compatibility with the latest Tendermint version. so either reset changes in src/messages/*
or you can run make update-proto
src/messages/abci.rs
Outdated
@@ -7550,7 +7550,7 @@ impl ::protobuf::reflect::ProtobufValue for ResponseCommit { | |||
#[derive(PartialEq,Clone,Default)] | |||
pub struct ConsensusParams { | |||
// message fields | |||
pub block: ::protobuf::SingularPtrField<BlockParams>, | |||
pub block_size: ::protobuf::SingularPtrField<BlockSizeParams>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@enginespot seems this overrides the latest changes from protobuf definitions -- Tendermint 0.2* had block_size
, but 0.3* has block
-- see https://github.com/tendermint/rust-abci/pull/48/files
src/messages/merkle.rs
Outdated
@@ -443,8 +443,8 @@ static file_descriptor_proto_data: &'static [u8] = b"\ | |||
rkle\">\n\x07ProofOp\x12\x10\n\x04type\x18\x01\x20\x01(\tB\x02\x18\0\x12\ | |||
\x0f\n\x03key\x18\x02\x20\x01(\x0cB\x02\x18\0\x12\x10\n\x04data\x18\x03\ | |||
\x20\x01(\x0cB\x02\x18\0\")\n\x05Proof\x12\x20\n\x03ops\x18\x01\x20\x03(\ | |||
\x0b2\x0f.merkle.ProofOpB\x02\x18\0B\x14\xa8\xe2\x1e\x01\xe0\xe2\x1e\x01\ | |||
\xd0\xe2\x1e\x01\xc8\xe2\x1e\x01\xf8\xe1\x1e\x01b\x06proto3\ | |||
\x0b2\x0f.merkle.ProofOpB\x02\x18\0B\x14\xc8\xe2\x1e\x01\xf8\xe1\x1e\x01\ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
again this probably reverts the latest tendermint protobuf changes https://github.com/tendermint/rust-abci/pull/48/files
src/messages/types.rs
Outdated
@@ -429,8 +429,8 @@ static file_descriptor_proto_data: &'static [u8] = b"\ | |||
n\",\n\x06KVPair\x12\x0f\n\x03key\x18\x01\x20\x01(\x0cB\x02\x18\0\x12\ | |||
\x11\n\x05value\x18\x02\x20\x01(\x0cB\x02\x18\0\".\n\x08KI64Pair\x12\x0f\ | |||
\n\x03key\x18\x01\x20\x01(\x0cB\x02\x18\0\x12\x11\n\x05value\x18\x02\x20\ | |||
\x01(\x03B\x02\x18\0B\x1c\xd0\xe2\x1e\x01\xc0\xe3\x1e\x01\xe0\xe2\x1e\ | |||
\x01\xa8\xe2\x1e\x01\xf8\xe1\x1e\x01\xb8\xe2\x1e\x01\xc8\xe2\x1e\x01b\ | |||
\x01(\x03B\x02\x18\0B\x1c\xa8\xe2\x1e\x01\xc0\xe3\x1e\x01\xd0\xe2\x1e\ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as mentioned before https://github.com/tendermint/rust-abci/pull/48/files
@tomtau you should have merge perms now (?). Can you squash-merge this to master and then create a PR that merges master to develop? All sub-sequent PRs should be against develop instead of master (only PRs that are there to trigger then next release should be from develop to master). |
- Changed to try_init, if init twice program panics - Added into example apps the init of the logger - Bump package Version Signed-off-by: Marko Baricevic <[email protected]>
… enginespot-master
Add Asynchronous processing support #31