Browse Source

Conform to TMSP v0.2

pull/192/head
Jae Kwon 9 years ago
parent
commit
236c7afe9e
10 changed files with 48 additions and 85 deletions
  1. +1
    -1
      benchmarks/simu/counter.go
  2. +1
    -1
      mempool/mempool.go
  3. +13
    -12
      mempool/mempool_test.go
  4. +1
    -1
      node/node.go
  5. +3
    -5
      proxy/app_conn.go
  6. +14
    -43
      proxy/local_app_conn.go
  7. +1
    -1
      proxy/remote_app_conn.go
  8. +1
    -1
      proxy/remote_app_conn_test.go
  9. +9
    -8
      state/execution.go
  10. +4
    -12
      types/events.go

+ 1
- 1
benchmarks/simu/counter.go View File

@ -36,7 +36,7 @@ func main() {
// Make a bunch of requests
buf := make([]byte, 32)
for i := 0; ; i++ {
binary.LittleEndian.PutUint64(buf, uint64(i))
binary.BigEndian.PutUint64(buf, uint64(i))
//txBytes := hex.EncodeToString(buf[:n])
request := rpctypes.NewRPCRequest("fakeid", "broadcast_tx", Arr(buf[:8]))
reqBytes := wire.JSONBytes(request)


+ 1
- 1
mempool/mempool.go View File

@ -105,7 +105,7 @@ func (mem *Mempool) resCb(req tmsp.Request, res tmsp.Response) {
switch res := res.(type) {
case tmsp.ResponseCheckTx:
reqCheckTx := req.(tmsp.RequestCheckTx)
if res.RetCode == tmsp.RetCodeOK {
if res.Code == tmsp.RetCodeOK {
mem.counter++
memTx := &mempoolTx{
counter: mem.counter,


+ 13
- 12
mempool/mempool_test.go View File

@ -25,8 +25,8 @@ func TestSerialReap(t *testing.T) {
for i := start; i < end; i++ {
// This will succeed
txBytes := make([]byte, 32)
binary.LittleEndian.PutUint64(txBytes, uint64(i))
txBytes := make([]byte, 8)
binary.BigEndian.PutUint64(txBytes, uint64(i))
err := mempool.CheckTx(txBytes)
if err != nil {
t.Fatal("Error after CheckTx: %v", err)
@ -56,8 +56,8 @@ func TestSerialReap(t *testing.T) {
updateRange := func(start, end int) {
txs := make([]types.Tx, 0)
for i := start; i < end; i++ {
txBytes := make([]byte, 32)
binary.LittleEndian.PutUint64(txBytes, uint64(i))
txBytes := make([]byte, 8)
binary.BigEndian.PutUint64(txBytes, uint64(i))
txs = append(txs, txBytes)
}
err := mempool.Update(0, txs)
@ -69,16 +69,17 @@ func TestSerialReap(t *testing.T) {
commitRange := func(start, end int) {
// Append some txs.
for i := start; i < end; i++ {
txBytes := make([]byte, 32)
binary.LittleEndian.PutUint64(txBytes, uint64(i))
_, retCode := appConnCon.AppendTx(txBytes)
if retCode != tmsp.RetCodeOK {
t.Error("Error committing tx", retCode)
txBytes := make([]byte, 8)
binary.BigEndian.PutUint64(txBytes, uint64(i))
code, result, logStr := appConnCon.AppendTx(txBytes)
if code != tmsp.RetCodeOK {
t.Errorf("Error committing tx. Code:%v result:%X log:%v",
code, result, logStr)
}
}
_, retCode := appConnCon.GetHash()
if retCode != tmsp.RetCodeOK {
t.Error("Error committing range", retCode)
hash, log := appConnCon.GetHash()
if len(hash) != 8 {
t.Errorf("Error getting hash. Hash:%X log:%v", hash, log)
}
}


+ 1
- 1
node/node.go View File

@ -315,7 +315,7 @@ func getProxyApp(addr string, hash []byte) (proxyAppConn proxy.AppConn) {
}
// Check the hash
currentHash, err := proxyAppConn.GetHashSync()
currentHash, _, err := proxyAppConn.GetHashSync()
if err != nil {
PanicCrisis(Fmt("Error in getting proxyAppConn hash: %v", err))
}


+ 3
- 5
proxy/app_conn.go View File

@ -1,7 +1,7 @@
package proxy
import (
tmspcli "github.com/tendermint/tmsp/client/golang"
tmspcli "github.com/tendermint/tmsp/client"
)
type AppConn interface {
@ -14,10 +14,8 @@ type AppConn interface {
CheckTxAsync(tx []byte)
GetHashAsync()
SetOptionAsync(key string, value string)
AddListenerAsync(key string)
RemListenerAsync(key string)
InfoSync() (info []string, err error)
InfoSync() (info string, err error)
FlushSync() error
GetHashSync() (hash []byte, err error)
GetHashSync() (hash []byte, log string, err error)
}

+ 14
- 43
proxy/local_app_conn.go View File

@ -1,7 +1,7 @@
package proxy
import (
tmspcli "github.com/tendermint/tmsp/client/golang"
tmspcli "github.com/tendermint/tmsp/client"
tmsp "github.com/tendermint/tmsp/types"
"sync"
)
@ -31,12 +31,9 @@ func (app *localAppConn) Error() error {
}
func (app *localAppConn) EchoAsync(msg string) {
app.mtx.Lock()
msg2 := app.Application.Echo(msg)
app.mtx.Unlock()
app.Callback(
tmsp.RequestEcho{msg},
tmsp.ResponseEcho{msg2},
tmsp.ResponseEcho{msg},
)
}
@ -46,71 +43,45 @@ func (app *localAppConn) FlushAsync() {
func (app *localAppConn) SetOptionAsync(key string, value string) {
app.mtx.Lock()
retCode := app.Application.SetOption(key, value)
log := app.Application.SetOption(key, value)
app.mtx.Unlock()
app.Callback(
tmsp.RequestSetOption{key, value},
tmsp.ResponseSetOption{retCode},
tmsp.ResponseSetOption{log},
)
}
func (app *localAppConn) AppendTxAsync(tx []byte) {
app.mtx.Lock()
events, retCode := app.Application.AppendTx(tx)
code, result, log := app.Application.AppendTx(tx)
app.mtx.Unlock()
app.Callback(
tmsp.RequestAppendTx{tx},
tmsp.ResponseAppendTx{retCode},
tmsp.ResponseAppendTx{code, result, log},
)
for _, event := range events {
app.Callback(
nil,
tmsp.ResponseEvent{event},
)
}
}
func (app *localAppConn) CheckTxAsync(tx []byte) {
app.mtx.Lock()
retCode := app.Application.CheckTx(tx)
code, result, log := app.Application.CheckTx(tx)
app.mtx.Unlock()
app.Callback(
tmsp.RequestCheckTx{tx},
tmsp.ResponseCheckTx{retCode},
tmsp.ResponseCheckTx{code, result, log},
)
}
func (app *localAppConn) GetHashAsync() {
app.mtx.Lock()
hash, retCode := app.Application.GetHash()
hash, log := app.Application.GetHash()
app.mtx.Unlock()
app.Callback(
tmsp.RequestGetHash{},
tmsp.ResponseGetHash{retCode, hash},
)
}
func (app *localAppConn) AddListenerAsync(key string) {
app.mtx.Lock()
retCode := app.Application.AddListener(key)
app.mtx.Unlock()
app.Callback(
tmsp.RequestAddListener{key},
tmsp.ResponseAddListener{retCode},
)
}
func (app *localAppConn) RemListenerAsync(key string) {
app.mtx.Lock()
retCode := app.Application.RemListener(key)
app.mtx.Unlock()
app.Callback(
tmsp.RequestRemListener{key},
tmsp.ResponseRemListener{retCode},
tmsp.ResponseGetHash{hash, log},
)
}
func (app *localAppConn) InfoSync() (info []string, err error) {
func (app *localAppConn) InfoSync() (info string, err error) {
app.mtx.Lock()
info = app.Application.Info()
app.mtx.Unlock()
@ -121,9 +92,9 @@ func (app *localAppConn) FlushSync() error {
return nil
}
func (app *localAppConn) GetHashSync() (hash []byte, err error) {
func (app *localAppConn) GetHashSync() (hash []byte, log string, err error) {
app.mtx.Lock()
hash, retCode := app.Application.GetHash()
hash, log = app.Application.GetHash()
app.mtx.Unlock()
return hash, retCode.Error()
return hash, log, nil
}

+ 1
- 1
proxy/remote_app_conn.go View File

@ -3,7 +3,7 @@ package proxy
import (
"net"
tmspcli "github.com/tendermint/tmsp/client/golang"
tmspcli "github.com/tendermint/tmsp/client"
)
// This is goroutine-safe, but users should beware that


+ 1
- 1
proxy/remote_app_conn_test.go View File

@ -92,7 +92,7 @@ func TestInfo(t *testing.T) {
if err != nil {
t.Errorf("Unexpected error: %v", err)
}
if data[0] != "size:0" {
if data != "size:0" {
t.Error("Expected ResponseInfo with one element 'size:0' but got something else")
}
}

+ 9
- 8
state/execution.go View File

@ -63,17 +63,15 @@ func (s *State) execBlockOnProxyApp(evsw *events.EventSwitch, proxyAppConn proxy
proxyCb := func(req tmsp.Request, res tmsp.Response) {
switch res := res.(type) {
case tmsp.ResponseAppendTx:
// TODO: make use of res.Log
// TODO: make use of this info
// Blocks may include invalid txs.
// reqAppendTx := req.(tmsp.RequestAppendTx)
if res.RetCode == tmsp.RetCodeOK {
if res.Code == tmsp.RetCodeOK {
validTxs += 1
} else {
invalidTxs += 1
}
case tmsp.ResponseEvent:
// TODO: some events should get stored in the blockchain.
evsw.FireEvent(types.EventStringApp(), types.EventDataApp{res.Key, res.Data})
}
}
proxyAppConn.SetResponseCallback(proxyCb)
@ -85,11 +83,14 @@ func (s *State) execBlockOnProxyApp(evsw *events.EventSwitch, proxyAppConn proxy
return err
}
}
hash, err := proxyAppConn.GetHashSync()
hash, logStr, err := proxyAppConn.GetHashSync()
if err != nil {
log.Warn("Error computing proxyAppConn hash", "error", err)
return err
}
if logStr != "" {
log.Debug("GetHash.Log: " + logStr)
}
log.Info(Fmt("ExecBlock got %v valid txs and %v invalid txs", validTxs, invalidTxs))
// Set the state's new AppHash
@ -156,10 +157,10 @@ func updateValidatorsWithBlock(lastValSet *types.ValidatorSet, valSet *types.Val
//-----------------------------------------------------------------------------
type InvalidTxError struct {
Tx types.Tx
tmsp.RetCode
Tx types.Tx
Code tmsp.RetCode
}
func (txErr InvalidTxError) Error() string {
return Fmt("Invalid tx: [%v] code: [%v]", txErr.Tx, txErr.RetCode)
return Fmt("Invalid tx: [%v] code: [%v]", txErr.Tx, txErr.Code)
}

+ 4
- 12
types/events.go View File

@ -26,7 +26,6 @@ func EventStringLock() string { return "Lock" }
func EventStringRelock() string { return "Relock" }
func EventStringTimeoutWait() string { return "TimeoutWait" }
func EventStringVote() string { return "Vote" }
func EventStringApp() string { return "App" }
//----------------------------------------
@ -40,7 +39,6 @@ const (
EventDataTypeNewBlock = byte(0x01)
EventDataTypeFork = byte(0x02)
EventDataTypeTx = byte(0x03)
EventDataTypeApp = byte(0x04) // Custom app event
EventDataTypeRoundState = byte(0x11)
EventDataTypeVote = byte(0x12)
@ -51,7 +49,6 @@ var _ = wire.RegisterInterface(
wire.ConcreteType{EventDataNewBlock{}, EventDataTypeNewBlock},
// wire.ConcreteType{EventDataFork{}, EventDataTypeFork },
wire.ConcreteType{EventDataTx{}, EventDataTypeTx},
wire.ConcreteType{EventDataApp{}, EventDataTypeApp},
wire.ConcreteType{EventDataRoundState{}, EventDataTypeRoundState},
wire.ConcreteType{EventDataVote{}, EventDataTypeVote},
)
@ -65,14 +62,10 @@ type EventDataNewBlock struct {
// All txs fire EventDataTx
type EventDataTx struct {
Tx Tx `json:"tx"`
Return []byte `json:"return"`
Exception string `json:"exception"`
}
type EventDataApp struct {
Key string `json:"key"`
Data []byte `json:"bytes"`
Tx Tx `json:"tx"`
Result []byte `json:"result"`
Log string `json:"log"`
Error string `json:"error"`
}
type EventDataRoundState struct {
@ -92,6 +85,5 @@ type EventDataVote struct {
func (_ EventDataNewBlock) AssertIsTMEventData() {}
func (_ EventDataTx) AssertIsTMEventData() {}
func (_ EventDataApp) AssertIsTMEventData() {}
func (_ EventDataRoundState) AssertIsTMEventData() {}
func (_ EventDataVote) AssertIsTMEventData() {}

Loading…
Cancel
Save