Browse Source

QuitService->BaseService

pull/1780/head
Jae Kwon 8 years ago
committed by Ethan Buchman
parent
commit
7998ba668a
5 changed files with 22 additions and 18 deletions
  1. +5
    -1
      README.md
  2. +4
    -4
      client/grpc_client.go
  3. +5
    -5
      client/socket_client.go
  4. +4
    -4
      server/grpc_server.go
  5. +4
    -4
      server/socket_server.go

+ 5
- 1
README.md View File

@ -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__:<br/>
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.


+ 4
- 4
client/grpc_client.go View File

@ -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()


+ 5
- 5
client/socket_client.go View File

@ -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)


+ 4
- 4
server/grpc_server.go View File

@ -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()
}

+ 4
- 4
server/socket_server.go View File

@ -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()


Loading…
Cancel
Save