Merge branch 'tmsp_v02'
This commit is contained in:
commit
24af8e3da2
|
@ -36,7 +36,7 @@ func main() {
|
||||||
// Make a bunch of requests
|
// Make a bunch of requests
|
||||||
buf := make([]byte, 32)
|
buf := make([]byte, 32)
|
||||||
for i := 0; ; i++ {
|
for i := 0; ; i++ {
|
||||||
binary.LittleEndian.PutUint64(buf, uint64(i))
|
binary.BigEndian.PutUint64(buf, uint64(i))
|
||||||
//txBytes := hex.EncodeToString(buf[:n])
|
//txBytes := hex.EncodeToString(buf[:n])
|
||||||
request := rpctypes.NewRPCRequest("fakeid", "broadcast_tx", Arr(buf[:8]))
|
request := rpctypes.NewRPCRequest("fakeid", "broadcast_tx", Arr(buf[:8]))
|
||||||
reqBytes := wire.JSONBytes(request)
|
reqBytes := wire.JSONBytes(request)
|
||||||
|
|
|
@ -105,7 +105,7 @@ func (mem *Mempool) resCb(req tmsp.Request, res tmsp.Response) {
|
||||||
switch res := res.(type) {
|
switch res := res.(type) {
|
||||||
case tmsp.ResponseCheckTx:
|
case tmsp.ResponseCheckTx:
|
||||||
reqCheckTx := req.(tmsp.RequestCheckTx)
|
reqCheckTx := req.(tmsp.RequestCheckTx)
|
||||||
if res.RetCode == tmsp.RetCodeOK {
|
if res.Code == tmsp.RetCodeOK {
|
||||||
mem.counter++
|
mem.counter++
|
||||||
memTx := &mempoolTx{
|
memTx := &mempoolTx{
|
||||||
counter: mem.counter,
|
counter: mem.counter,
|
||||||
|
|
|
@ -25,8 +25,8 @@ func TestSerialReap(t *testing.T) {
|
||||||
for i := start; i < end; i++ {
|
for i := start; i < end; i++ {
|
||||||
|
|
||||||
// This will succeed
|
// This will succeed
|
||||||
txBytes := make([]byte, 32)
|
txBytes := make([]byte, 8)
|
||||||
binary.LittleEndian.PutUint64(txBytes, uint64(i))
|
binary.BigEndian.PutUint64(txBytes, uint64(i))
|
||||||
err := mempool.CheckTx(txBytes)
|
err := mempool.CheckTx(txBytes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal("Error after CheckTx: %v", err)
|
t.Fatal("Error after CheckTx: %v", err)
|
||||||
|
@ -56,8 +56,8 @@ func TestSerialReap(t *testing.T) {
|
||||||
updateRange := func(start, end int) {
|
updateRange := func(start, end int) {
|
||||||
txs := make([]types.Tx, 0)
|
txs := make([]types.Tx, 0)
|
||||||
for i := start; i < end; i++ {
|
for i := start; i < end; i++ {
|
||||||
txBytes := make([]byte, 32)
|
txBytes := make([]byte, 8)
|
||||||
binary.LittleEndian.PutUint64(txBytes, uint64(i))
|
binary.BigEndian.PutUint64(txBytes, uint64(i))
|
||||||
txs = append(txs, txBytes)
|
txs = append(txs, txBytes)
|
||||||
}
|
}
|
||||||
err := mempool.Update(0, txs)
|
err := mempool.Update(0, txs)
|
||||||
|
@ -69,16 +69,17 @@ func TestSerialReap(t *testing.T) {
|
||||||
commitRange := func(start, end int) {
|
commitRange := func(start, end int) {
|
||||||
// Append some txs.
|
// Append some txs.
|
||||||
for i := start; i < end; i++ {
|
for i := start; i < end; i++ {
|
||||||
txBytes := make([]byte, 32)
|
txBytes := make([]byte, 8)
|
||||||
binary.LittleEndian.PutUint64(txBytes, uint64(i))
|
binary.BigEndian.PutUint64(txBytes, uint64(i))
|
||||||
_, retCode := appConnCon.AppendTx(txBytes)
|
code, result, logStr := appConnCon.AppendTx(txBytes)
|
||||||
if retCode != tmsp.RetCodeOK {
|
if code != tmsp.RetCodeOK {
|
||||||
t.Error("Error committing tx", retCode)
|
t.Errorf("Error committing tx. Code:%v result:%X log:%v",
|
||||||
|
code, result, logStr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_, retCode := appConnCon.GetHash()
|
hash, log := appConnCon.GetHash()
|
||||||
if retCode != tmsp.RetCodeOK {
|
if len(hash) != 8 {
|
||||||
t.Error("Error committing range", retCode)
|
t.Errorf("Error getting hash. Hash:%X log:%v", hash, log)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -245,7 +245,7 @@ func getProxyApp(addr string, hash []byte) (proxyAppConn proxy.AppConn) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check the hash
|
// Check the hash
|
||||||
currentHash, err := proxyAppConn.GetHashSync()
|
currentHash, _, err := proxyAppConn.GetHashSync()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
PanicCrisis(Fmt("Error in getting proxyAppConn hash: %v", err))
|
PanicCrisis(Fmt("Error in getting proxyAppConn hash: %v", err))
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package proxy
|
package proxy
|
||||||
|
|
||||||
import (
|
import (
|
||||||
tmspcli "github.com/tendermint/tmsp/client/golang"
|
tmspcli "github.com/tendermint/tmsp/client"
|
||||||
)
|
)
|
||||||
|
|
||||||
type AppConn interface {
|
type AppConn interface {
|
||||||
|
@ -14,10 +14,8 @@ type AppConn interface {
|
||||||
CheckTxAsync(tx []byte)
|
CheckTxAsync(tx []byte)
|
||||||
GetHashAsync()
|
GetHashAsync()
|
||||||
SetOptionAsync(key string, value string)
|
SetOptionAsync(key string, value string)
|
||||||
AddListenerAsync(key string)
|
|
||||||
RemListenerAsync(key string)
|
|
||||||
|
|
||||||
InfoSync() (info []string, err error)
|
InfoSync() (info string, err error)
|
||||||
FlushSync() error
|
FlushSync() error
|
||||||
GetHashSync() (hash []byte, err error)
|
GetHashSync() (hash []byte, log string, err error)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package proxy
|
package proxy
|
||||||
|
|
||||||
import (
|
import (
|
||||||
tmspcli "github.com/tendermint/tmsp/client/golang"
|
tmspcli "github.com/tendermint/tmsp/client"
|
||||||
tmsp "github.com/tendermint/tmsp/types"
|
tmsp "github.com/tendermint/tmsp/types"
|
||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
|
@ -31,12 +31,9 @@ func (app *localAppConn) Error() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (app *localAppConn) EchoAsync(msg string) {
|
func (app *localAppConn) EchoAsync(msg string) {
|
||||||
app.mtx.Lock()
|
|
||||||
msg2 := app.Application.Echo(msg)
|
|
||||||
app.mtx.Unlock()
|
|
||||||
app.Callback(
|
app.Callback(
|
||||||
tmsp.RequestEcho{msg},
|
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) {
|
func (app *localAppConn) SetOptionAsync(key string, value string) {
|
||||||
app.mtx.Lock()
|
app.mtx.Lock()
|
||||||
retCode := app.Application.SetOption(key, value)
|
log := app.Application.SetOption(key, value)
|
||||||
app.mtx.Unlock()
|
app.mtx.Unlock()
|
||||||
app.Callback(
|
app.Callback(
|
||||||
tmsp.RequestSetOption{key, value},
|
tmsp.RequestSetOption{key, value},
|
||||||
tmsp.ResponseSetOption{retCode},
|
tmsp.ResponseSetOption{log},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (app *localAppConn) AppendTxAsync(tx []byte) {
|
func (app *localAppConn) AppendTxAsync(tx []byte) {
|
||||||
app.mtx.Lock()
|
app.mtx.Lock()
|
||||||
events, retCode := app.Application.AppendTx(tx)
|
code, result, log := app.Application.AppendTx(tx)
|
||||||
app.mtx.Unlock()
|
app.mtx.Unlock()
|
||||||
app.Callback(
|
app.Callback(
|
||||||
tmsp.RequestAppendTx{tx},
|
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) {
|
func (app *localAppConn) CheckTxAsync(tx []byte) {
|
||||||
app.mtx.Lock()
|
app.mtx.Lock()
|
||||||
retCode := app.Application.CheckTx(tx)
|
code, result, log := app.Application.CheckTx(tx)
|
||||||
app.mtx.Unlock()
|
app.mtx.Unlock()
|
||||||
app.Callback(
|
app.Callback(
|
||||||
tmsp.RequestCheckTx{tx},
|
tmsp.RequestCheckTx{tx},
|
||||||
tmsp.ResponseCheckTx{retCode},
|
tmsp.ResponseCheckTx{code, result, log},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (app *localAppConn) GetHashAsync() {
|
func (app *localAppConn) GetHashAsync() {
|
||||||
app.mtx.Lock()
|
app.mtx.Lock()
|
||||||
hash, retCode := app.Application.GetHash()
|
hash, log := app.Application.GetHash()
|
||||||
app.mtx.Unlock()
|
app.mtx.Unlock()
|
||||||
app.Callback(
|
app.Callback(
|
||||||
tmsp.RequestGetHash{},
|
tmsp.RequestGetHash{},
|
||||||
tmsp.ResponseGetHash{retCode, hash},
|
tmsp.ResponseGetHash{hash, log},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (app *localAppConn) AddListenerAsync(key string) {
|
func (app *localAppConn) InfoSync() (info string, err error) {
|
||||||
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},
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (app *localAppConn) InfoSync() (info []string, err error) {
|
|
||||||
app.mtx.Lock()
|
app.mtx.Lock()
|
||||||
info = app.Application.Info()
|
info = app.Application.Info()
|
||||||
app.mtx.Unlock()
|
app.mtx.Unlock()
|
||||||
|
@ -121,9 +92,9 @@ func (app *localAppConn) FlushSync() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (app *localAppConn) GetHashSync() (hash []byte, err error) {
|
func (app *localAppConn) GetHashSync() (hash []byte, log string, err error) {
|
||||||
app.mtx.Lock()
|
app.mtx.Lock()
|
||||||
hash, retCode := app.Application.GetHash()
|
hash, log = app.Application.GetHash()
|
||||||
app.mtx.Unlock()
|
app.mtx.Unlock()
|
||||||
return hash, retCode.Error()
|
return hash, log, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ package proxy
|
||||||
import (
|
import (
|
||||||
"net"
|
"net"
|
||||||
|
|
||||||
tmspcli "github.com/tendermint/tmsp/client/golang"
|
tmspcli "github.com/tendermint/tmsp/client"
|
||||||
)
|
)
|
||||||
|
|
||||||
// This is goroutine-safe, but users should beware that
|
// This is goroutine-safe, but users should beware that
|
||||||
|
|
|
@ -92,7 +92,7 @@ func TestInfo(t *testing.T) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Unexpected error: %v", err)
|
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")
|
t.Error("Expected ResponseInfo with one element 'size:0' but got something else")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,17 +63,15 @@ func (s *State) execBlockOnProxyApp(evsw *events.EventSwitch, proxyAppConn proxy
|
||||||
proxyCb := func(req tmsp.Request, res tmsp.Response) {
|
proxyCb := func(req tmsp.Request, res tmsp.Response) {
|
||||||
switch res := res.(type) {
|
switch res := res.(type) {
|
||||||
case tmsp.ResponseAppendTx:
|
case tmsp.ResponseAppendTx:
|
||||||
|
// TODO: make use of res.Log
|
||||||
// TODO: make use of this info
|
// TODO: make use of this info
|
||||||
// Blocks may include invalid txs.
|
// Blocks may include invalid txs.
|
||||||
// reqAppendTx := req.(tmsp.RequestAppendTx)
|
// reqAppendTx := req.(tmsp.RequestAppendTx)
|
||||||
if res.RetCode == tmsp.RetCodeOK {
|
if res.Code == tmsp.RetCodeOK {
|
||||||
validTxs += 1
|
validTxs += 1
|
||||||
} else {
|
} else {
|
||||||
invalidTxs += 1
|
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)
|
proxyAppConn.SetResponseCallback(proxyCb)
|
||||||
|
@ -85,11 +83,14 @@ func (s *State) execBlockOnProxyApp(evsw *events.EventSwitch, proxyAppConn proxy
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
hash, err := proxyAppConn.GetHashSync()
|
hash, logStr, err := proxyAppConn.GetHashSync()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warn("Error computing proxyAppConn hash", "error", err)
|
log.Warn("Error computing proxyAppConn hash", "error", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
if logStr != "" {
|
||||||
|
log.Debug("GetHash.Log: " + logStr)
|
||||||
|
}
|
||||||
log.Info(Fmt("ExecBlock got %v valid txs and %v invalid txs", validTxs, invalidTxs))
|
log.Info(Fmt("ExecBlock got %v valid txs and %v invalid txs", validTxs, invalidTxs))
|
||||||
|
|
||||||
// Set the state's new AppHash
|
// Set the state's new AppHash
|
||||||
|
@ -156,10 +157,10 @@ func updateValidatorsWithBlock(lastValSet *types.ValidatorSet, valSet *types.Val
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
type InvalidTxError struct {
|
type InvalidTxError struct {
|
||||||
Tx types.Tx
|
Tx types.Tx
|
||||||
tmsp.RetCode
|
Code tmsp.RetCode
|
||||||
}
|
}
|
||||||
|
|
||||||
func (txErr InvalidTxError) Error() string {
|
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)
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,6 @@ func EventStringLock() string { return "Lock" }
|
||||||
func EventStringRelock() string { return "Relock" }
|
func EventStringRelock() string { return "Relock" }
|
||||||
func EventStringTimeoutWait() string { return "TimeoutWait" }
|
func EventStringTimeoutWait() string { return "TimeoutWait" }
|
||||||
func EventStringVote() string { return "Vote" }
|
func EventStringVote() string { return "Vote" }
|
||||||
func EventStringApp() string { return "App" }
|
|
||||||
|
|
||||||
//----------------------------------------
|
//----------------------------------------
|
||||||
|
|
||||||
|
@ -40,7 +39,6 @@ const (
|
||||||
EventDataTypeNewBlock = byte(0x01)
|
EventDataTypeNewBlock = byte(0x01)
|
||||||
EventDataTypeFork = byte(0x02)
|
EventDataTypeFork = byte(0x02)
|
||||||
EventDataTypeTx = byte(0x03)
|
EventDataTypeTx = byte(0x03)
|
||||||
EventDataTypeApp = byte(0x04) // Custom app event
|
|
||||||
|
|
||||||
EventDataTypeRoundState = byte(0x11)
|
EventDataTypeRoundState = byte(0x11)
|
||||||
EventDataTypeVote = byte(0x12)
|
EventDataTypeVote = byte(0x12)
|
||||||
|
@ -51,7 +49,6 @@ var _ = wire.RegisterInterface(
|
||||||
wire.ConcreteType{EventDataNewBlock{}, EventDataTypeNewBlock},
|
wire.ConcreteType{EventDataNewBlock{}, EventDataTypeNewBlock},
|
||||||
// wire.ConcreteType{EventDataFork{}, EventDataTypeFork },
|
// wire.ConcreteType{EventDataFork{}, EventDataTypeFork },
|
||||||
wire.ConcreteType{EventDataTx{}, EventDataTypeTx},
|
wire.ConcreteType{EventDataTx{}, EventDataTypeTx},
|
||||||
wire.ConcreteType{EventDataApp{}, EventDataTypeApp},
|
|
||||||
wire.ConcreteType{EventDataRoundState{}, EventDataTypeRoundState},
|
wire.ConcreteType{EventDataRoundState{}, EventDataTypeRoundState},
|
||||||
wire.ConcreteType{EventDataVote{}, EventDataTypeVote},
|
wire.ConcreteType{EventDataVote{}, EventDataTypeVote},
|
||||||
)
|
)
|
||||||
|
@ -65,14 +62,10 @@ type EventDataNewBlock struct {
|
||||||
|
|
||||||
// All txs fire EventDataTx
|
// All txs fire EventDataTx
|
||||||
type EventDataTx struct {
|
type EventDataTx struct {
|
||||||
Tx Tx `json:"tx"`
|
Tx Tx `json:"tx"`
|
||||||
Return []byte `json:"return"`
|
Result []byte `json:"result"`
|
||||||
Exception string `json:"exception"`
|
Log string `json:"log"`
|
||||||
}
|
Error string `json:"error"`
|
||||||
|
|
||||||
type EventDataApp struct {
|
|
||||||
Key string `json:"key"`
|
|
||||||
Data []byte `json:"bytes"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NOTE: This goes into the replay WAL
|
// NOTE: This goes into the replay WAL
|
||||||
|
@ -93,6 +86,5 @@ type EventDataVote struct {
|
||||||
|
|
||||||
func (_ EventDataNewBlock) AssertIsTMEventData() {}
|
func (_ EventDataNewBlock) AssertIsTMEventData() {}
|
||||||
func (_ EventDataTx) AssertIsTMEventData() {}
|
func (_ EventDataTx) AssertIsTMEventData() {}
|
||||||
func (_ EventDataApp) AssertIsTMEventData() {}
|
|
||||||
func (_ EventDataRoundState) AssertIsTMEventData() {}
|
func (_ EventDataRoundState) AssertIsTMEventData() {}
|
||||||
func (_ EventDataVote) AssertIsTMEventData() {}
|
func (_ EventDataVote) AssertIsTMEventData() {}
|
||||||
|
|
Loading…
Reference in New Issue