From 7998ba668ab8d11448f46925b7d8c6c8165a2126 Mon Sep 17 00:00:00 2001 From: Jae Kwon Date: Fri, 28 Oct 2016 12:06:40 -0700 Subject: [PATCH] QuitService->BaseService --- README.md | 6 +++++- client/grpc_client.go | 8 ++++---- client/socket_client.go | 10 +++++----- server/grpc_server.go | 8 ++++---- server/socket_server.go | 8 ++++---- 5 files changed, 22 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index d034a6b16..d6f1e53a8 100644 --- a/README.md +++ b/README.md @@ -68,7 +68,11 @@ TMSP requests/responses are simple Protobuf messages. Check out the [schema fil * `Data ([]byte)`: Result bytes, if any * `Log (string)`: Debug or error message * __Usage__:
- Validate a transaction. This message should not mutate the state. + Validate a mempool transaction, prior to broadcasting or proposing. This message should not mutate the main state, but application + developers may want to keep a separate CheckTx state that gets reset upon Commit. + + CheckTx can happen interspersed with AppendTx, but they happen on different connections - CheckTx from the mempool connection, and AppendTx from the consensus connection. During Commit, the mempool is locked, so you can reset the mempool state to the latest state after running all those appendtxs, and then the mempool will re run whatever txs it has against that latest mempool stte + Transactions are first run through CheckTx before broadcast to peers in the mempool layer. You can make CheckTx semi-stateful and clear the state upon `Commit` or `BeginBlock`, to allow for dependent sequences of transactions in the same block. diff --git a/client/grpc_client.go b/client/grpc_client.go index 771302c19..0c1ecf1c5 100644 --- a/client/grpc_client.go +++ b/client/grpc_client.go @@ -15,7 +15,7 @@ import ( // A stripped copy of the remoteClient that makes // synchronous calls using grpc type grpcClient struct { - QuitService + BaseService mustConnect bool client types.TMSPApplicationClient @@ -31,7 +31,7 @@ func NewGRPCClient(addr string, mustConnect bool) (*grpcClient, error) { addr: addr, mustConnect: mustConnect, } - cli.QuitService = *NewQuitService(nil, "grpcClient", cli) + cli.BaseService = *NewBaseService(nil, "grpcClient", cli) _, err := cli.Start() // Just start it, it's confusing for callers to remember to start. return cli, err } @@ -41,7 +41,7 @@ func dialerFunc(addr string, timeout time.Duration) (net.Conn, error) { } func (cli *grpcClient) OnStart() error { - cli.QuitService.OnStart() + cli.BaseService.OnStart() RETRY_LOOP: for { @@ -73,7 +73,7 @@ RETRY_LOOP: } func (cli *grpcClient) OnStop() { - cli.QuitService.OnStop() + cli.BaseService.OnStop() cli.mtx.Lock() defer cli.mtx.Unlock() // TODO: how to close conn? its not a net.Conn and grpc doesn't expose a Close() diff --git a/client/socket_client.go b/client/socket_client.go index 27e74787c..0b7be91d9 100644 --- a/client/socket_client.go +++ b/client/socket_client.go @@ -27,7 +27,7 @@ const flushThrottleMS = 20 // Don't wait longer than... // the application in general is not meant to be interfaced // with concurrent callers. type socketClient struct { - QuitService + BaseService reqQueue chan *ReqRes flushTimer *ThrottleTimer @@ -52,14 +52,14 @@ func NewSocketClient(addr string, mustConnect bool) (*socketClient, error) { reqSent: list.New(), resCb: nil, } - cli.QuitService = *NewQuitService(nil, "socketClient", cli) + cli.BaseService = *NewBaseService(nil, "socketClient", cli) _, err := cli.Start() // Just start it, it's confusing for callers to remember to start. return cli, err } func (cli *socketClient) OnStart() error { - cli.QuitService.OnStart() + cli.BaseService.OnStart() var err error var conn net.Conn @@ -86,7 +86,7 @@ RETRY_LOOP: } func (cli *socketClient) OnStop() { - cli.QuitService.OnStop() + cli.BaseService.OnStop() cli.mtx.Lock() defer cli.mtx.Unlock() @@ -140,7 +140,7 @@ func (cli *socketClient) sendRequestsRoutine(conn net.Conn) { default: // Probably will fill the buffer, or retry later. } - case <-cli.QuitService.Quit: + case <-cli.BaseService.Quit: return case reqres := <-cli.reqQueue: cli.willSendReq(reqres) diff --git a/server/grpc_server.go b/server/grpc_server.go index 02f6fa3f8..472da25dd 100644 --- a/server/grpc_server.go +++ b/server/grpc_server.go @@ -13,7 +13,7 @@ import ( // var maxNumberConnections = 2 type GRPCServer struct { - QuitService + BaseService proto string addr string @@ -32,13 +32,13 @@ func NewGRPCServer(protoAddr string, app types.TMSPApplicationServer) (Service, listener: nil, app: app, } - s.QuitService = *NewQuitService(nil, "TMSPServer", s) + s.BaseService = *NewBaseService(nil, "TMSPServer", s) _, err := s.Start() // Just start it return s, err } func (s *GRPCServer) OnStart() error { - s.QuitService.OnStart() + s.BaseService.OnStart() ln, err := net.Listen(s.proto, s.addr) if err != nil { return err @@ -51,6 +51,6 @@ func (s *GRPCServer) OnStart() error { } func (s *GRPCServer) OnStop() { - s.QuitService.OnStop() + s.BaseService.OnStop() s.server.Stop() } diff --git a/server/socket_server.go b/server/socket_server.go index ff01a9082..3eec302fb 100644 --- a/server/socket_server.go +++ b/server/socket_server.go @@ -15,7 +15,7 @@ import ( // var maxNumberConnections = 2 type SocketServer struct { - QuitService + BaseService proto string addr string @@ -39,13 +39,13 @@ func NewSocketServer(protoAddr string, app types.Application) (Service, error) { app: app, conns: make(map[int]net.Conn), } - s.QuitService = *NewQuitService(nil, "TMSPServer", s) + s.BaseService = *NewBaseService(nil, "TMSPServer", s) _, err := s.Start() // Just start it return s, err } func (s *SocketServer) OnStart() error { - s.QuitService.OnStart() + s.BaseService.OnStart() ln, err := net.Listen(s.proto, s.addr) if err != nil { return err @@ -56,7 +56,7 @@ func (s *SocketServer) OnStart() error { } func (s *SocketServer) OnStop() { - s.QuitService.OnStop() + s.BaseService.OnStop() s.listener.Close() s.connsMtx.Lock()