mirror of
https://github.com/fluencelabs/tendermint
synced 2025-05-23 19:31:18 +00:00
commit
a33b75fe8b
@ -5,11 +5,11 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/tendermint/abci/types"
|
"github.com/tendermint/abci/types"
|
||||||
. "github.com/tendermint/go-common"
|
common "github.com/tendermint/go-common"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Client interface {
|
type Client interface {
|
||||||
Service
|
common.Service
|
||||||
|
|
||||||
SetResponseCallback(Callback)
|
SetResponseCallback(Callback)
|
||||||
Error() error
|
Error() error
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package abcicli
|
package abcicli
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
@ -9,13 +10,13 @@ import (
|
|||||||
grpc "google.golang.org/grpc"
|
grpc "google.golang.org/grpc"
|
||||||
|
|
||||||
"github.com/tendermint/abci/types"
|
"github.com/tendermint/abci/types"
|
||||||
. "github.com/tendermint/go-common"
|
common "github.com/tendermint/go-common"
|
||||||
)
|
)
|
||||||
|
|
||||||
// A stripped copy of the remoteClient that makes
|
// A stripped copy of the remoteClient that makes
|
||||||
// synchronous calls using grpc
|
// synchronous calls using grpc
|
||||||
type grpcClient struct {
|
type grpcClient struct {
|
||||||
BaseService
|
common.BaseService
|
||||||
mustConnect bool
|
mustConnect bool
|
||||||
|
|
||||||
client types.ABCIApplicationClient
|
client types.ABCIApplicationClient
|
||||||
@ -31,13 +32,13 @@ func NewGRPCClient(addr string, mustConnect bool) (*grpcClient, error) {
|
|||||||
addr: addr,
|
addr: addr,
|
||||||
mustConnect: mustConnect,
|
mustConnect: mustConnect,
|
||||||
}
|
}
|
||||||
cli.BaseService = *NewBaseService(nil, "grpcClient", cli)
|
cli.BaseService = *common.NewBaseService(nil, "grpcClient", cli)
|
||||||
_, err := cli.Start() // Just start it, it's confusing for callers to remember to start.
|
_, err := cli.Start() // Just start it, it's confusing for callers to remember to start.
|
||||||
return cli, err
|
return cli, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func dialerFunc(addr string, timeout time.Duration) (net.Conn, error) {
|
func dialerFunc(addr string, timeout time.Duration) (net.Conn, error) {
|
||||||
return Connect(addr)
|
return common.Connect(addr)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cli *grpcClient) OnStart() error {
|
func (cli *grpcClient) OnStart() error {
|
||||||
@ -49,11 +50,10 @@ RETRY_LOOP:
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
if cli.mustConnect {
|
if cli.mustConnect {
|
||||||
return err
|
return err
|
||||||
} else {
|
|
||||||
log.Warn(Fmt("abci.grpcClient failed to connect to %v. Retrying...\n", cli.addr))
|
|
||||||
time.Sleep(time.Second * 3)
|
|
||||||
continue RETRY_LOOP
|
|
||||||
}
|
}
|
||||||
|
log.Warn(fmt.Sprintf("abci.grpcClient failed to connect to %v. Retrying...\n", cli.addr))
|
||||||
|
time.Sleep(time.Second * 3)
|
||||||
|
continue RETRY_LOOP
|
||||||
}
|
}
|
||||||
|
|
||||||
client := types.NewABCIApplicationClient(conn)
|
client := types.NewABCIApplicationClient(conn)
|
||||||
@ -93,7 +93,7 @@ func (cli *grpcClient) StopForError(err error) {
|
|||||||
}
|
}
|
||||||
cli.mtx.Unlock()
|
cli.mtx.Unlock()
|
||||||
|
|
||||||
log.Warn(Fmt("Stopping abci.grpcClient for error: %v", err.Error()))
|
log.Warn(fmt.Sprintf("Stopping abci.grpcClient for error: %v", err.Error()))
|
||||||
cli.Stop()
|
cli.Stop()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -267,11 +267,10 @@ func (cli *grpcClient) InfoSync() (resInfo types.ResponseInfo, err error) {
|
|||||||
if err = cli.Error(); err != nil {
|
if err = cli.Error(); err != nil {
|
||||||
return resInfo, err
|
return resInfo, err
|
||||||
}
|
}
|
||||||
if resInfo_ := reqres.Response.GetInfo(); resInfo_ != nil {
|
if info := reqres.Response.GetInfo(); info != nil {
|
||||||
return *resInfo_, nil
|
return *info, nil
|
||||||
} else {
|
|
||||||
return resInfo, nil
|
|
||||||
}
|
}
|
||||||
|
return resInfo, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cli *grpcClient) SetOptionSync(key string, value string) (res types.Result) {
|
func (cli *grpcClient) SetOptionSync(key string, value string) (res types.Result) {
|
||||||
@ -334,9 +333,8 @@ func (cli *grpcClient) EndBlockSync(height uint64) (resEndBlock types.ResponseEn
|
|||||||
if err := cli.Error(); err != nil {
|
if err := cli.Error(); err != nil {
|
||||||
return resEndBlock, err
|
return resEndBlock, err
|
||||||
}
|
}
|
||||||
if resEndBlock_ := reqres.Response.GetEndBlock(); resEndBlock_ != nil {
|
if blk := reqres.Response.GetEndBlock(); blk != nil {
|
||||||
return *resEndBlock_, nil
|
return *blk, nil
|
||||||
} else {
|
|
||||||
return resEndBlock, nil
|
|
||||||
}
|
}
|
||||||
|
return resEndBlock, nil
|
||||||
}
|
}
|
||||||
|
@ -4,11 +4,11 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
types "github.com/tendermint/abci/types"
|
types "github.com/tendermint/abci/types"
|
||||||
. "github.com/tendermint/go-common"
|
common "github.com/tendermint/go-common"
|
||||||
)
|
)
|
||||||
|
|
||||||
type localClient struct {
|
type localClient struct {
|
||||||
BaseService
|
common.BaseService
|
||||||
mtx *sync.Mutex
|
mtx *sync.Mutex
|
||||||
types.Application
|
types.Application
|
||||||
Callback
|
Callback
|
||||||
@ -22,7 +22,7 @@ func NewLocalClient(mtx *sync.Mutex, app types.Application) *localClient {
|
|||||||
mtx: mtx,
|
mtx: mtx,
|
||||||
Application: app,
|
Application: app,
|
||||||
}
|
}
|
||||||
cli.BaseService = *NewBaseService(log, "localClient", cli)
|
cli.BaseService = *common.NewBaseService(log, "localClient", cli)
|
||||||
return cli
|
return cli
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/tendermint/abci/types"
|
"github.com/tendermint/abci/types"
|
||||||
. "github.com/tendermint/go-common"
|
common "github.com/tendermint/go-common"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -27,10 +27,10 @@ const flushThrottleMS = 20 // Don't wait longer than...
|
|||||||
// the application in general is not meant to be interfaced
|
// the application in general is not meant to be interfaced
|
||||||
// with concurrent callers.
|
// with concurrent callers.
|
||||||
type socketClient struct {
|
type socketClient struct {
|
||||||
BaseService
|
common.BaseService
|
||||||
|
|
||||||
reqQueue chan *ReqRes
|
reqQueue chan *ReqRes
|
||||||
flushTimer *ThrottleTimer
|
flushTimer *common.ThrottleTimer
|
||||||
mustConnect bool
|
mustConnect bool
|
||||||
|
|
||||||
mtx sync.Mutex
|
mtx sync.Mutex
|
||||||
@ -45,14 +45,14 @@ type socketClient struct {
|
|||||||
func NewSocketClient(addr string, mustConnect bool) (*socketClient, error) {
|
func NewSocketClient(addr string, mustConnect bool) (*socketClient, error) {
|
||||||
cli := &socketClient{
|
cli := &socketClient{
|
||||||
reqQueue: make(chan *ReqRes, reqQueueSize),
|
reqQueue: make(chan *ReqRes, reqQueueSize),
|
||||||
flushTimer: NewThrottleTimer("socketClient", flushThrottleMS),
|
flushTimer: common.NewThrottleTimer("socketClient", flushThrottleMS),
|
||||||
mustConnect: mustConnect,
|
mustConnect: mustConnect,
|
||||||
|
|
||||||
addr: addr,
|
addr: addr,
|
||||||
reqSent: list.New(),
|
reqSent: list.New(),
|
||||||
resCb: nil,
|
resCb: nil,
|
||||||
}
|
}
|
||||||
cli.BaseService = *NewBaseService(nil, "socketClient", cli)
|
cli.BaseService = *common.NewBaseService(nil, "socketClient", cli)
|
||||||
|
|
||||||
_, err := cli.Start() // Just start it, it's confusing for callers to remember to start.
|
_, err := cli.Start() // Just start it, it's confusing for callers to remember to start.
|
||||||
return cli, err
|
return cli, err
|
||||||
@ -65,15 +65,14 @@ func (cli *socketClient) OnStart() error {
|
|||||||
var conn net.Conn
|
var conn net.Conn
|
||||||
RETRY_LOOP:
|
RETRY_LOOP:
|
||||||
for {
|
for {
|
||||||
conn, err = Connect(cli.addr)
|
conn, err = common.Connect(cli.addr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if cli.mustConnect {
|
if cli.mustConnect {
|
||||||
return err
|
return err
|
||||||
} else {
|
|
||||||
log.Warn(Fmt("abci.socketClient failed to connect to %v. Retrying...", cli.addr))
|
|
||||||
time.Sleep(time.Second * 3)
|
|
||||||
continue RETRY_LOOP
|
|
||||||
}
|
}
|
||||||
|
log.Warn(fmt.Sprintf("abci.socketClient failed to connect to %v. Retrying...", cli.addr))
|
||||||
|
time.Sleep(time.Second * 3)
|
||||||
|
continue RETRY_LOOP
|
||||||
}
|
}
|
||||||
cli.conn = conn
|
cli.conn = conn
|
||||||
|
|
||||||
@ -82,7 +81,6 @@ RETRY_LOOP:
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return nil // never happens
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cli *socketClient) OnStop() {
|
func (cli *socketClient) OnStop() {
|
||||||
@ -109,7 +107,7 @@ func (cli *socketClient) StopForError(err error) {
|
|||||||
}
|
}
|
||||||
cli.mtx.Unlock()
|
cli.mtx.Unlock()
|
||||||
|
|
||||||
log.Warn(Fmt("Stopping abci.socketClient for error: %v", err.Error()))
|
log.Warn(fmt.Sprintf("Stopping abci.socketClient for error: %v", err.Error()))
|
||||||
cli.Stop()
|
cli.Stop()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -298,11 +296,10 @@ func (cli *socketClient) InfoSync() (resInfo types.ResponseInfo, err error) {
|
|||||||
if err := cli.Error(); err != nil {
|
if err := cli.Error(); err != nil {
|
||||||
return resInfo, err
|
return resInfo, err
|
||||||
}
|
}
|
||||||
if resInfo_ := reqres.Response.GetInfo(); resInfo_ != nil {
|
if info := reqres.Response.GetInfo(); info != nil {
|
||||||
return *resInfo_, nil
|
return *info, nil
|
||||||
} else {
|
|
||||||
return resInfo, nil
|
|
||||||
}
|
}
|
||||||
|
return resInfo, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cli *socketClient) SetOptionSync(key string, value string) (res types.Result) {
|
func (cli *socketClient) SetOptionSync(key string, value string) (res types.Result) {
|
||||||
@ -379,11 +376,10 @@ func (cli *socketClient) EndBlockSync(height uint64) (resEndBlock types.Response
|
|||||||
if err := cli.Error(); err != nil {
|
if err := cli.Error(); err != nil {
|
||||||
return resEndBlock, err
|
return resEndBlock, err
|
||||||
}
|
}
|
||||||
if resEndBlock_ := reqres.Response.GetEndBlock(); resEndBlock_ != nil {
|
if blk := reqres.Response.GetEndBlock(); blk != nil {
|
||||||
return *resEndBlock_, nil
|
return *blk, nil
|
||||||
} else {
|
|
||||||
return resEndBlock, nil
|
|
||||||
}
|
}
|
||||||
|
return resEndBlock, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------
|
//----------------------------------------
|
||||||
|
@ -6,12 +6,12 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/tendermint/abci/client"
|
"github.com/tendermint/abci/client"
|
||||||
"github.com/tendermint/abci/types"
|
"github.com/tendermint/abci/types"
|
||||||
. "github.com/tendermint/go-common"
|
|
||||||
"github.com/urfave/cli"
|
"github.com/urfave/cli"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -135,7 +135,7 @@ func main() {
|
|||||||
app.Before = before
|
app.Before = before
|
||||||
err := app.Run(os.Args)
|
err := app.Run(os.Args)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Exit(err.Error())
|
log.Fatal(err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -145,7 +145,7 @@ func before(c *cli.Context) error {
|
|||||||
var err error
|
var err error
|
||||||
client, err = abcicli.NewClient(c.GlobalString("address"), c.GlobalString("abci"), false)
|
client, err = abcicli.NewClient(c.GlobalString("address"), c.GlobalString("abci"), false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Exit(err.Error())
|
log.Fatal(err.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
@ -244,7 +244,7 @@ func cmdSetOption(c *cli.Context) error {
|
|||||||
return errors.New("Command set_option takes 2 arguments (key, value)")
|
return errors.New("Command set_option takes 2 arguments (key, value)")
|
||||||
}
|
}
|
||||||
res := client.SetOptionSync(args[0], args[1])
|
res := client.SetOptionSync(args[0], args[1])
|
||||||
rsp := newResponse(res, Fmt("%s=%s", args[0], args[1]), false)
|
rsp := newResponse(res, fmt.Sprintf("%s=%s", args[0], args[1]), false)
|
||||||
printResponse(c, rsp)
|
printResponse(c, rsp)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -284,7 +284,7 @@ func cmdCheckTx(c *cli.Context) error {
|
|||||||
// Get application Merkle root hash
|
// Get application Merkle root hash
|
||||||
func cmdCommit(c *cli.Context) error {
|
func cmdCommit(c *cli.Context) error {
|
||||||
res := client.CommitSync()
|
res := client.CommitSync()
|
||||||
rsp := newResponse(res, Fmt("0x%X", res.Data), false)
|
rsp := newResponse(res, fmt.Sprintf("0x%X", res.Data), false)
|
||||||
printResponse(c, rsp)
|
printResponse(c, rsp)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -2,10 +2,11 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
|
"log"
|
||||||
|
|
||||||
"github.com/tendermint/abci/example/counter"
|
"github.com/tendermint/abci/example/counter"
|
||||||
"github.com/tendermint/abci/server"
|
"github.com/tendermint/abci/server"
|
||||||
. "github.com/tendermint/go-common"
|
common "github.com/tendermint/go-common"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@ -19,11 +20,11 @@ func main() {
|
|||||||
// Start the listener
|
// Start the listener
|
||||||
srv, err := server.NewServer(*addrPtr, *abciPtr, app)
|
srv, err := server.NewServer(*addrPtr, *abciPtr, app)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Exit(err.Error())
|
log.Fatal(err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wait forever
|
// Wait forever
|
||||||
TrapSignal(func() {
|
common.TrapSignal(func() {
|
||||||
// Cleanup
|
// Cleanup
|
||||||
srv.Stop()
|
srv.Stop()
|
||||||
})
|
})
|
||||||
|
@ -2,11 +2,12 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
|
"log"
|
||||||
|
|
||||||
"github.com/tendermint/abci/example/dummy"
|
"github.com/tendermint/abci/example/dummy"
|
||||||
"github.com/tendermint/abci/server"
|
"github.com/tendermint/abci/server"
|
||||||
"github.com/tendermint/abci/types"
|
"github.com/tendermint/abci/types"
|
||||||
. "github.com/tendermint/go-common"
|
common "github.com/tendermint/go-common"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@ -27,11 +28,11 @@ func main() {
|
|||||||
// Start the listener
|
// Start the listener
|
||||||
srv, err := server.NewServer(*addrPtr, *abciPtr, app)
|
srv, err := server.NewServer(*addrPtr, *abciPtr, app)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Exit(err.Error())
|
log.Fatal(err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wait forever
|
// Wait forever
|
||||||
TrapSignal(func() {
|
common.TrapSignal(func() {
|
||||||
// Cleanup
|
// Cleanup
|
||||||
srv.Stop()
|
srv.Stop()
|
||||||
})
|
})
|
||||||
|
@ -2,10 +2,12 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
|
||||||
"github.com/tendermint/abci/server"
|
"github.com/tendermint/abci/server"
|
||||||
"github.com/tendermint/abci/types"
|
"github.com/tendermint/abci/types"
|
||||||
. "github.com/tendermint/go-common"
|
common "github.com/tendermint/go-common"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@ -17,11 +19,11 @@ func main() {
|
|||||||
// Start the listener
|
// Start the listener
|
||||||
srv, err := server.NewServer(*addrPtr, *abciPtr, NewChainAwareApplication())
|
srv, err := server.NewServer(*addrPtr, *abciPtr, NewChainAwareApplication())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Exit(err.Error())
|
log.Fatal(err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wait forever
|
// Wait forever
|
||||||
TrapSignal(func() {
|
common.TrapSignal(func() {
|
||||||
// Cleanup
|
// Cleanup
|
||||||
srv.Stop()
|
srv.Stop()
|
||||||
})
|
})
|
||||||
@ -58,16 +60,16 @@ func (app *ChainAwareApplication) Commit() types.Result {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (app *ChainAwareApplication) Query(query []byte) types.Result {
|
func (app *ChainAwareApplication) Query(query []byte) types.Result {
|
||||||
return types.NewResultOK([]byte(Fmt("%d,%d", app.beginCount, app.endCount)), "")
|
return types.NewResultOK([]byte(fmt.Sprintf("%d,%d", app.beginCount, app.endCount)), "")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (app *ChainAwareApplication) BeginBlock(hash []byte, header *types.Header) {
|
func (app *ChainAwareApplication) BeginBlock(hash []byte, header *types.Header) {
|
||||||
app.beginCount += 1
|
app.beginCount++
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (app *ChainAwareApplication) EndBlock(height uint64) (resEndBlock types.ResponseEndBlock) {
|
func (app *ChainAwareApplication) EndBlock(height uint64) (resEndBlock types.ResponseEndBlock) {
|
||||||
app.endCount += 1
|
app.endCount++
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
@ -8,7 +10,6 @@ import (
|
|||||||
"github.com/tendermint/abci/client"
|
"github.com/tendermint/abci/client"
|
||||||
"github.com/tendermint/abci/server"
|
"github.com/tendermint/abci/server"
|
||||||
"github.com/tendermint/abci/types"
|
"github.com/tendermint/abci/types"
|
||||||
. "github.com/tendermint/go-common"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestChainAware(t *testing.T) {
|
func TestChainAware(t *testing.T) {
|
||||||
@ -25,7 +26,7 @@ func TestChainAware(t *testing.T) {
|
|||||||
// Connect to the socket
|
// Connect to the socket
|
||||||
client, err := abcicli.NewSocketClient("unix://test.sock", false)
|
client, err := abcicli.NewSocketClient("unix://test.sock", false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Exit(Fmt("Error starting socket client: %v", err.Error()))
|
log.Fatal(fmt.Sprintf("Error starting socket client: %v", err.Error()))
|
||||||
}
|
}
|
||||||
client.Start()
|
client.Start()
|
||||||
defer client.Stop()
|
defer client.Stop()
|
||||||
|
@ -2,9 +2,9 @@ package counter
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"github.com/tendermint/abci/types"
|
"github.com/tendermint/abci/types"
|
||||||
. "github.com/tendermint/go-common"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type CounterApplication struct {
|
type CounterApplication struct {
|
||||||
@ -18,7 +18,7 @@ func NewCounterApplication(serial bool) *CounterApplication {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (app *CounterApplication) Info() types.ResponseInfo {
|
func (app *CounterApplication) Info() types.ResponseInfo {
|
||||||
return types.ResponseInfo{Data: Fmt("{\"hashes\":%v,\"txs\":%v}", app.hashCount, app.txCount)}
|
return types.ResponseInfo{Data: fmt.Sprintf("{\"hashes\":%v,\"txs\":%v}", app.hashCount, app.txCount)}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (app *CounterApplication) SetOption(key string, value string) (log string) {
|
func (app *CounterApplication) SetOption(key string, value string) (log string) {
|
||||||
@ -31,44 +31,42 @@ func (app *CounterApplication) SetOption(key string, value string) (log string)
|
|||||||
func (app *CounterApplication) DeliverTx(tx []byte) types.Result {
|
func (app *CounterApplication) DeliverTx(tx []byte) types.Result {
|
||||||
if app.serial {
|
if app.serial {
|
||||||
if len(tx) > 8 {
|
if len(tx) > 8 {
|
||||||
return types.ErrEncodingError.SetLog(Fmt("Max tx size is 8 bytes, got %d", len(tx)))
|
return types.ErrEncodingError.SetLog(fmt.Sprintf("Max tx size is 8 bytes, got %d", len(tx)))
|
||||||
}
|
}
|
||||||
tx8 := make([]byte, 8)
|
tx8 := make([]byte, 8)
|
||||||
copy(tx8[len(tx8)-len(tx):], tx)
|
copy(tx8[len(tx8)-len(tx):], tx)
|
||||||
txValue := binary.BigEndian.Uint64(tx8)
|
txValue := binary.BigEndian.Uint64(tx8)
|
||||||
if txValue != uint64(app.txCount) {
|
if txValue != uint64(app.txCount) {
|
||||||
return types.ErrBadNonce.SetLog(Fmt("Invalid nonce. Expected %v, got %v", app.txCount, txValue))
|
return types.ErrBadNonce.SetLog(fmt.Sprintf("Invalid nonce. Expected %v, got %v", app.txCount, txValue))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
app.txCount += 1
|
app.txCount++
|
||||||
return types.OK
|
return types.OK
|
||||||
}
|
}
|
||||||
|
|
||||||
func (app *CounterApplication) CheckTx(tx []byte) types.Result {
|
func (app *CounterApplication) CheckTx(tx []byte) types.Result {
|
||||||
if app.serial {
|
if app.serial {
|
||||||
if len(tx) > 8 {
|
if len(tx) > 8 {
|
||||||
return types.ErrEncodingError.SetLog(Fmt("Max tx size is 8 bytes, got %d", len(tx)))
|
return types.ErrEncodingError.SetLog(fmt.Sprintf("Max tx size is 8 bytes, got %d", len(tx)))
|
||||||
}
|
}
|
||||||
tx8 := make([]byte, 8)
|
tx8 := make([]byte, 8)
|
||||||
copy(tx8[len(tx8)-len(tx):], tx)
|
copy(tx8[len(tx8)-len(tx):], tx)
|
||||||
txValue := binary.BigEndian.Uint64(tx8)
|
txValue := binary.BigEndian.Uint64(tx8)
|
||||||
if txValue < uint64(app.txCount) {
|
if txValue < uint64(app.txCount) {
|
||||||
return types.ErrBadNonce.SetLog(Fmt("Invalid nonce. Expected >= %v, got %v", app.txCount, txValue))
|
return types.ErrBadNonce.SetLog(fmt.Sprintf("Invalid nonce. Expected >= %v, got %v", app.txCount, txValue))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return types.OK
|
return types.OK
|
||||||
}
|
}
|
||||||
|
|
||||||
func (app *CounterApplication) Commit() types.Result {
|
func (app *CounterApplication) Commit() types.Result {
|
||||||
app.hashCount += 1
|
app.hashCount++
|
||||||
|
|
||||||
if app.txCount == 0 {
|
if app.txCount == 0 {
|
||||||
return types.OK
|
return types.OK
|
||||||
} else {
|
|
||||||
hash := make([]byte, 8)
|
|
||||||
binary.BigEndian.PutUint64(hash, uint64(app.txCount))
|
|
||||||
return types.NewResultOK(hash, "")
|
|
||||||
}
|
}
|
||||||
|
hash := make([]byte, 8)
|
||||||
|
binary.BigEndian.PutUint64(hash, uint64(app.txCount))
|
||||||
|
return types.NewResultOK(hash, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (app *CounterApplication) Query(query []byte) types.Result {
|
func (app *CounterApplication) Query(query []byte) types.Result {
|
||||||
@ -76,10 +74,10 @@ func (app *CounterApplication) Query(query []byte) types.Result {
|
|||||||
|
|
||||||
switch queryStr {
|
switch queryStr {
|
||||||
case "hash":
|
case "hash":
|
||||||
return types.NewResultOK(nil, Fmt("%v", app.hashCount))
|
return types.NewResultOK(nil, fmt.Sprintf("%v", app.hashCount))
|
||||||
case "tx":
|
case "tx":
|
||||||
return types.NewResultOK(nil, Fmt("%v", app.txCount))
|
return types.NewResultOK(nil, fmt.Sprintf("%v", app.txCount))
|
||||||
}
|
}
|
||||||
|
|
||||||
return types.ErrUnknownRequest.SetLog(Fmt("Invalid nonce. Expected hash or tx, got %v", queryStr))
|
return types.ErrUnknownRequest.SetLog(fmt.Sprintf("Invalid nonce. Expected hash or tx, got %v", queryStr))
|
||||||
}
|
}
|
||||||
|
@ -2,10 +2,10 @@ package dummy
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/tendermint/abci/types"
|
"github.com/tendermint/abci/types"
|
||||||
. "github.com/tendermint/go-common"
|
|
||||||
"github.com/tendermint/go-merkle"
|
"github.com/tendermint/go-merkle"
|
||||||
"github.com/tendermint/go-wire"
|
"github.com/tendermint/go-wire"
|
||||||
)
|
)
|
||||||
@ -20,7 +20,7 @@ func NewDummyApplication() *DummyApplication {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (app *DummyApplication) Info() (resInfo types.ResponseInfo) {
|
func (app *DummyApplication) Info() (resInfo types.ResponseInfo) {
|
||||||
return types.ResponseInfo{Data: Fmt("{\"size\":%v}", app.state.Size())}
|
return types.ResponseInfo{Data: fmt.Sprintf("{\"size\":%v}", app.state.Size())}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (app *DummyApplication) SetOption(key string, value string) (log string) {
|
func (app *DummyApplication) SetOption(key string, value string) (log string) {
|
||||||
|
@ -2,12 +2,13 @@ package dummy
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"sort"
|
"sort"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/tendermint/abci/types"
|
"github.com/tendermint/abci/types"
|
||||||
. "github.com/tendermint/go-common"
|
common "github.com/tendermint/go-common"
|
||||||
"github.com/tendermint/go-crypto"
|
"github.com/tendermint/go-crypto"
|
||||||
"github.com/tendermint/go-wire"
|
"github.com/tendermint/go-wire"
|
||||||
)
|
)
|
||||||
@ -107,8 +108,8 @@ func TestValSetChanges(t *testing.T) {
|
|||||||
nInit := 5
|
nInit := 5
|
||||||
vals := make([]*types.Validator, total)
|
vals := make([]*types.Validator, total)
|
||||||
for i := 0; i < total; i++ {
|
for i := 0; i < total; i++ {
|
||||||
pubkey := crypto.GenPrivKeyEd25519FromSecret([]byte(Fmt("test%d", i))).PubKey().Bytes()
|
pubkey := crypto.GenPrivKeyEd25519FromSecret([]byte(fmt.Sprintf("test%d", i))).PubKey().Bytes()
|
||||||
power := RandInt()
|
power := common.RandInt()
|
||||||
vals[i] = &types.Validator{pubkey, uint64(power)}
|
vals[i] = &types.Validator{pubkey, uint64(power)}
|
||||||
}
|
}
|
||||||
// iniitalize with the first nInit
|
// iniitalize with the first nInit
|
||||||
|
@ -3,11 +3,12 @@ package dummy
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
|
"fmt"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/tendermint/abci/types"
|
"github.com/tendermint/abci/types"
|
||||||
. "github.com/tendermint/go-common"
|
common "github.com/tendermint/go-common"
|
||||||
dbm "github.com/tendermint/go-db"
|
dbm "github.com/tendermint/go-db"
|
||||||
"github.com/tendermint/go-merkle"
|
"github.com/tendermint/go-merkle"
|
||||||
"github.com/tendermint/go-wire"
|
"github.com/tendermint/go-wire"
|
||||||
@ -135,7 +136,7 @@ func LoadLastBlock(db dbm.DB) (lastBlock LastBlockInfo) {
|
|||||||
wire.ReadBinaryPtr(&lastBlock, r, 0, n, err)
|
wire.ReadBinaryPtr(&lastBlock, r, 0, n, err)
|
||||||
if *err != nil {
|
if *err != nil {
|
||||||
// DATA HAS BEEN CORRUPTED OR THE SPEC HAS CHANGED
|
// DATA HAS BEEN CORRUPTED OR THE SPEC HAS CHANGED
|
||||||
Exit(Fmt("Data has been corrupted or its spec has changed: %v\n", *err))
|
log.Crit(fmt.Sprintf("Data has been corrupted or its spec has changed: %v\n", *err))
|
||||||
}
|
}
|
||||||
// TODO: ensure that buf is completely read.
|
// TODO: ensure that buf is completely read.
|
||||||
}
|
}
|
||||||
@ -149,7 +150,7 @@ func SaveLastBlock(db dbm.DB, lastBlock LastBlockInfo) {
|
|||||||
wire.WriteBinary(lastBlock, buf, n, err)
|
wire.WriteBinary(lastBlock, buf, n, err)
|
||||||
if *err != nil {
|
if *err != nil {
|
||||||
// TODO
|
// TODO
|
||||||
PanicCrisis(*err)
|
common.PanicCrisis(*err)
|
||||||
}
|
}
|
||||||
db.Set(lastBlockKey, buf.Bytes())
|
db.Set(lastBlockKey, buf.Bytes())
|
||||||
}
|
}
|
||||||
@ -173,7 +174,7 @@ func (app *PersistentDummyApplication) Validators() (validators []*types.Validat
|
|||||||
}
|
}
|
||||||
|
|
||||||
func MakeValSetChangeTx(pubkey []byte, power uint64) []byte {
|
func MakeValSetChangeTx(pubkey []byte, power uint64) []byte {
|
||||||
return []byte(Fmt("val:%X/%d", pubkey, power))
|
return []byte(fmt.Sprintf("val:%X/%d", pubkey, power))
|
||||||
}
|
}
|
||||||
|
|
||||||
func isValidatorTx(tx []byte) bool {
|
func isValidatorTx(tx []byte) bool {
|
||||||
@ -188,16 +189,16 @@ func (app *PersistentDummyApplication) execValidatorTx(tx []byte) types.Result {
|
|||||||
tx = tx[len(ValidatorSetChangePrefix):]
|
tx = tx[len(ValidatorSetChangePrefix):]
|
||||||
pubKeyAndPower := strings.Split(string(tx), "/")
|
pubKeyAndPower := strings.Split(string(tx), "/")
|
||||||
if len(pubKeyAndPower) != 2 {
|
if len(pubKeyAndPower) != 2 {
|
||||||
return types.ErrEncodingError.SetLog(Fmt("Expected 'pubkey/power'. Got %v", pubKeyAndPower))
|
return types.ErrEncodingError.SetLog(fmt.Sprintf("Expected 'pubkey/power'. Got %v", pubKeyAndPower))
|
||||||
}
|
}
|
||||||
pubkeyS, powerS := pubKeyAndPower[0], pubKeyAndPower[1]
|
pubkeyS, powerS := pubKeyAndPower[0], pubKeyAndPower[1]
|
||||||
pubkey, err := hex.DecodeString(pubkeyS)
|
pubkey, err := hex.DecodeString(pubkeyS)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return types.ErrEncodingError.SetLog(Fmt("Pubkey (%s) is invalid hex", pubkeyS))
|
return types.ErrEncodingError.SetLog(fmt.Sprintf("Pubkey (%s) is invalid hex", pubkeyS))
|
||||||
}
|
}
|
||||||
power, err := strconv.Atoi(powerS)
|
power, err := strconv.Atoi(powerS)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return types.ErrEncodingError.SetLog(Fmt("Power (%s) is not an int", powerS))
|
return types.ErrEncodingError.SetLog(fmt.Sprintf("Power (%s) is not an int", powerS))
|
||||||
}
|
}
|
||||||
|
|
||||||
// update
|
// update
|
||||||
@ -210,14 +211,14 @@ func (app *PersistentDummyApplication) updateValidator(v *types.Validator) types
|
|||||||
if v.Power == 0 {
|
if v.Power == 0 {
|
||||||
// remove validator
|
// remove validator
|
||||||
if !app.app.state.Has(key) {
|
if !app.app.state.Has(key) {
|
||||||
return types.ErrUnauthorized.SetLog(Fmt("Cannot remove non-existent validator %X", key))
|
return types.ErrUnauthorized.SetLog(fmt.Sprintf("Cannot remove non-existent validator %X", key))
|
||||||
}
|
}
|
||||||
app.app.state.Remove(key)
|
app.app.state.Remove(key)
|
||||||
} else {
|
} else {
|
||||||
// add or update validator
|
// add or update validator
|
||||||
value := bytes.NewBuffer(make([]byte, 0))
|
value := bytes.NewBuffer(make([]byte, 0))
|
||||||
if err := types.WriteMessage(v, value); err != nil {
|
if err := types.WriteMessage(v, value); err != nil {
|
||||||
return types.ErrInternalError.SetLog(Fmt("Error encoding validator: %v", err))
|
return types.ErrInternalError.SetLog(fmt.Sprintf("Error encoding validator: %v", err))
|
||||||
}
|
}
|
||||||
app.app.state.Set(key, value.Bytes())
|
app.app.state.Set(key, value.Bytes())
|
||||||
}
|
}
|
||||||
|
@ -2,20 +2,22 @@ package example
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
"net"
|
"net"
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"golang.org/x/net/context"
|
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
|
|
||||||
|
"golang.org/x/net/context"
|
||||||
|
|
||||||
"github.com/tendermint/abci/client"
|
"github.com/tendermint/abci/client"
|
||||||
"github.com/tendermint/abci/example/dummy"
|
"github.com/tendermint/abci/example/dummy"
|
||||||
nilapp "github.com/tendermint/abci/example/nil"
|
nilapp "github.com/tendermint/abci/example/nil"
|
||||||
"github.com/tendermint/abci/server"
|
"github.com/tendermint/abci/server"
|
||||||
"github.com/tendermint/abci/types"
|
"github.com/tendermint/abci/types"
|
||||||
. "github.com/tendermint/go-common"
|
common "github.com/tendermint/go-common"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestDummy(t *testing.T) {
|
func TestDummy(t *testing.T) {
|
||||||
@ -40,14 +42,14 @@ func testStream(t *testing.T, app types.Application) {
|
|||||||
// Start the listener
|
// Start the listener
|
||||||
server, err := server.NewSocketServer("unix://test.sock", app)
|
server, err := server.NewSocketServer("unix://test.sock", app)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Exit(Fmt("Error starting socket server: %v", err.Error()))
|
log.Fatal(fmt.Sprintf("Error starting socket server: %v", err.Error()))
|
||||||
}
|
}
|
||||||
defer server.Stop()
|
defer server.Stop()
|
||||||
|
|
||||||
// Connect to the socket
|
// Connect to the socket
|
||||||
client, err := abcicli.NewSocketClient("unix://test.sock", false)
|
client, err := abcicli.NewSocketClient("unix://test.sock", false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Exit(Fmt("Error starting socket client: %v", err.Error()))
|
log.Fatal(fmt.Sprintf("Error starting socket client: %v", err.Error()))
|
||||||
}
|
}
|
||||||
client.Start()
|
client.Start()
|
||||||
defer client.Stop()
|
defer client.Stop()
|
||||||
@ -58,7 +60,7 @@ func testStream(t *testing.T, app types.Application) {
|
|||||||
// Process response
|
// Process response
|
||||||
switch r := res.Value.(type) {
|
switch r := res.Value.(type) {
|
||||||
case *types.Response_DeliverTx:
|
case *types.Response_DeliverTx:
|
||||||
counter += 1
|
counter++
|
||||||
if r.DeliverTx.Code != types.CodeType_OK {
|
if r.DeliverTx.Code != types.CodeType_OK {
|
||||||
t.Error("DeliverTx failed with ret_code", r.DeliverTx.Code)
|
t.Error("DeliverTx failed with ret_code", r.DeliverTx.Code)
|
||||||
}
|
}
|
||||||
@ -103,7 +105,7 @@ func testStream(t *testing.T, app types.Application) {
|
|||||||
// test grpc
|
// test grpc
|
||||||
|
|
||||||
func dialerFunc(addr string, timeout time.Duration) (net.Conn, error) {
|
func dialerFunc(addr string, timeout time.Duration) (net.Conn, error) {
|
||||||
return Connect(addr)
|
return common.Connect(addr)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testGRPCSync(t *testing.T, app *types.GRPCApplication) {
|
func testGRPCSync(t *testing.T, app *types.GRPCApplication) {
|
||||||
@ -113,14 +115,14 @@ func testGRPCSync(t *testing.T, app *types.GRPCApplication) {
|
|||||||
// Start the listener
|
// Start the listener
|
||||||
server, err := server.NewGRPCServer("unix://test.sock", app)
|
server, err := server.NewGRPCServer("unix://test.sock", app)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Exit(Fmt("Error starting GRPC server: %v", err.Error()))
|
log.Fatal(fmt.Sprintf("Error starting GRPC server: %v", err.Error()))
|
||||||
}
|
}
|
||||||
defer server.Stop()
|
defer server.Stop()
|
||||||
|
|
||||||
// Connect to the socket
|
// Connect to the socket
|
||||||
conn, err := grpc.Dial("unix://test.sock", grpc.WithInsecure(), grpc.WithDialer(dialerFunc))
|
conn, err := grpc.Dial("unix://test.sock", grpc.WithInsecure(), grpc.WithDialer(dialerFunc))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Exit(Fmt("Error dialing GRPC server: %v", err.Error()))
|
log.Fatal(fmt.Sprintf("Error dialing GRPC server: %v", err.Error()))
|
||||||
}
|
}
|
||||||
defer conn.Close()
|
defer conn.Close()
|
||||||
|
|
||||||
@ -133,7 +135,7 @@ func testGRPCSync(t *testing.T, app *types.GRPCApplication) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Error in GRPC DeliverTx: %v", err.Error())
|
t.Fatalf("Error in GRPC DeliverTx: %v", err.Error())
|
||||||
}
|
}
|
||||||
counter += 1
|
counter++
|
||||||
if response.Code != types.CodeType_OK {
|
if response.Code != types.CodeType_OK {
|
||||||
t.Error("DeliverTx failed with ret_code", response.Code)
|
t.Error("DeliverTx failed with ret_code", response.Code)
|
||||||
}
|
}
|
||||||
|
@ -7,13 +7,13 @@ import (
|
|||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
|
|
||||||
"github.com/tendermint/abci/types"
|
"github.com/tendermint/abci/types"
|
||||||
. "github.com/tendermint/go-common"
|
common "github.com/tendermint/go-common"
|
||||||
)
|
)
|
||||||
|
|
||||||
// var maxNumberConnections = 2
|
// var maxNumberConnections = 2
|
||||||
|
|
||||||
type GRPCServer struct {
|
type GRPCServer struct {
|
||||||
BaseService
|
common.BaseService
|
||||||
|
|
||||||
proto string
|
proto string
|
||||||
addr string
|
addr string
|
||||||
@ -23,7 +23,7 @@ type GRPCServer struct {
|
|||||||
app types.ABCIApplicationServer
|
app types.ABCIApplicationServer
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewGRPCServer(protoAddr string, app types.ABCIApplicationServer) (Service, error) {
|
func NewGRPCServer(protoAddr string, app types.ABCIApplicationServer) (common.Service, error) {
|
||||||
parts := strings.SplitN(protoAddr, "://", 2)
|
parts := strings.SplitN(protoAddr, "://", 2)
|
||||||
proto, addr := parts[0], parts[1]
|
proto, addr := parts[0], parts[1]
|
||||||
s := &GRPCServer{
|
s := &GRPCServer{
|
||||||
@ -32,7 +32,7 @@ func NewGRPCServer(protoAddr string, app types.ABCIApplicationServer) (Service,
|
|||||||
listener: nil,
|
listener: nil,
|
||||||
app: app,
|
app: app,
|
||||||
}
|
}
|
||||||
s.BaseService = *NewBaseService(nil, "ABCIServer", s)
|
s.BaseService = *common.NewBaseService(nil, "ABCIServer", s)
|
||||||
_, err := s.Start() // Just start it
|
_, err := s.Start() // Just start it
|
||||||
return s, err
|
return s, err
|
||||||
}
|
}
|
||||||
|
@ -4,11 +4,11 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/tendermint/abci/types"
|
"github.com/tendermint/abci/types"
|
||||||
. "github.com/tendermint/go-common"
|
common "github.com/tendermint/go-common"
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewServer(protoAddr, transport string, app types.Application) (Service, error) {
|
func NewServer(protoAddr, transport string, app types.Application) (common.Service, error) {
|
||||||
var s Service
|
var s common.Service
|
||||||
var err error
|
var err error
|
||||||
switch transport {
|
switch transport {
|
||||||
case "socket":
|
case "socket":
|
||||||
|
@ -9,13 +9,13 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/tendermint/abci/types"
|
"github.com/tendermint/abci/types"
|
||||||
. "github.com/tendermint/go-common"
|
common "github.com/tendermint/go-common"
|
||||||
)
|
)
|
||||||
|
|
||||||
// var maxNumberConnections = 2
|
// var maxNumberConnections = 2
|
||||||
|
|
||||||
type SocketServer struct {
|
type SocketServer struct {
|
||||||
BaseService
|
common.BaseService
|
||||||
|
|
||||||
proto string
|
proto string
|
||||||
addr string
|
addr string
|
||||||
@ -29,7 +29,7 @@ type SocketServer struct {
|
|||||||
app types.Application
|
app types.Application
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewSocketServer(protoAddr string, app types.Application) (Service, error) {
|
func NewSocketServer(protoAddr string, app types.Application) (common.Service, error) {
|
||||||
parts := strings.SplitN(protoAddr, "://", 2)
|
parts := strings.SplitN(protoAddr, "://", 2)
|
||||||
proto, addr := parts[0], parts[1]
|
proto, addr := parts[0], parts[1]
|
||||||
s := &SocketServer{
|
s := &SocketServer{
|
||||||
@ -39,7 +39,7 @@ func NewSocketServer(protoAddr string, app types.Application) (Service, error) {
|
|||||||
app: app,
|
app: app,
|
||||||
conns: make(map[int]net.Conn),
|
conns: make(map[int]net.Conn),
|
||||||
}
|
}
|
||||||
s.BaseService = *NewBaseService(nil, "ABCIServer", s)
|
s.BaseService = *common.NewBaseService(nil, "ABCIServer", s)
|
||||||
_, err := s.Start() // Just start it
|
_, err := s.Start() // Just start it
|
||||||
return s, err
|
return s, err
|
||||||
}
|
}
|
||||||
@ -72,7 +72,7 @@ func (s *SocketServer) addConn(conn net.Conn) int {
|
|||||||
defer s.connsMtx.Unlock()
|
defer s.connsMtx.Unlock()
|
||||||
|
|
||||||
connID := s.nextConnID
|
connID := s.nextConnID
|
||||||
s.nextConnID += 1
|
s.nextConnID++
|
||||||
s.conns[connID] = conn
|
s.conns[connID] = conn
|
||||||
|
|
||||||
return connID
|
return connID
|
||||||
@ -100,7 +100,7 @@ func (s *SocketServer) acceptConnectionsRoutine() {
|
|||||||
if !s.IsRunning() {
|
if !s.IsRunning() {
|
||||||
return // Ignore error from listener closing.
|
return // Ignore error from listener closing.
|
||||||
}
|
}
|
||||||
Exit("Failed to accept connection: " + err.Error())
|
log.Crit("Failed to accept connection: " + err.Error())
|
||||||
} else {
|
} else {
|
||||||
log.Notice("Accepted a new connection")
|
log.Notice("Accepted a new connection")
|
||||||
}
|
}
|
||||||
|
@ -3,17 +3,17 @@ package main
|
|||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"fmt"
|
"fmt"
|
||||||
//"encoding/hex"
|
"log"
|
||||||
|
|
||||||
"github.com/tendermint/abci/types"
|
"github.com/tendermint/abci/types"
|
||||||
. "github.com/tendermint/go-common"
|
common "github.com/tendermint/go-common"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
conn, err := Connect("unix://test.sock")
|
conn, err := common.Connect("unix://test.sock")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Exit(err.Error())
|
log.Fatal(err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read a bunch of responses
|
// Read a bunch of responses
|
||||||
@ -23,9 +23,9 @@ func main() {
|
|||||||
var res = &types.Response{}
|
var res = &types.Response{}
|
||||||
err := types.ReadMessage(conn, res)
|
err := types.ReadMessage(conn, res)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Exit(err.Error())
|
log.Fatal(err.Error())
|
||||||
}
|
}
|
||||||
counter += 1
|
counter++
|
||||||
if counter%1000 == 0 {
|
if counter%1000 == 0 {
|
||||||
fmt.Println("Read", counter)
|
fmt.Println("Read", counter)
|
||||||
}
|
}
|
||||||
@ -40,14 +40,14 @@ func main() {
|
|||||||
|
|
||||||
err := types.WriteMessage(req, bufWriter)
|
err := types.WriteMessage(req, bufWriter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Exit(err.Error())
|
log.Fatal(err.Error())
|
||||||
}
|
}
|
||||||
err = bufWriter.Flush()
|
err = bufWriter.Flush()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Exit(err.Error())
|
log.Fatal(err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
counter += 1
|
counter++
|
||||||
if counter%1000 == 0 {
|
if counter%1000 == 0 {
|
||||||
fmt.Println("Write", counter)
|
fmt.Println("Write", counter)
|
||||||
}
|
}
|
||||||
|
@ -2,21 +2,20 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
"net"
|
"net"
|
||||||
"reflect"
|
"reflect"
|
||||||
//"encoding/hex"
|
|
||||||
|
|
||||||
"github.com/tendermint/abci/types"
|
"github.com/tendermint/abci/types"
|
||||||
. "github.com/tendermint/go-common"
|
common "github.com/tendermint/go-common"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
conn, err := Connect("unix://test.sock")
|
conn, err := common.Connect("unix://test.sock")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Exit(err.Error())
|
log.Fatal(err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make a bunch of requests
|
// Make a bunch of requests
|
||||||
@ -25,9 +24,9 @@ func main() {
|
|||||||
req := types.ToRequestEcho("foobar")
|
req := types.ToRequestEcho("foobar")
|
||||||
_, err := makeRequest(conn, req)
|
_, err := makeRequest(conn, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Exit(err.Error())
|
log.Fatal(err.Error())
|
||||||
}
|
}
|
||||||
counter += 1
|
counter++
|
||||||
if counter%1000 == 0 {
|
if counter%1000 == 0 {
|
||||||
fmt.Println(counter)
|
fmt.Println(counter)
|
||||||
}
|
}
|
||||||
@ -63,7 +62,7 @@ func makeRequest(conn net.Conn, req *types.Request) (*types.Response, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if _, ok := resFlush.Value.(*types.Response_Flush); !ok {
|
if _, ok := resFlush.Value.(*types.Response_Flush); !ok {
|
||||||
return nil, errors.New(Fmt("Expected flush response but got something else: %v", reflect.TypeOf(resFlush)))
|
return nil, fmt.Errorf("Expected flush response but got something else: %v", reflect.TypeOf(resFlush))
|
||||||
}
|
}
|
||||||
|
|
||||||
return res, nil
|
return res, nil
|
||||||
|
@ -2,18 +2,16 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/tendermint/abci/client"
|
"github.com/tendermint/abci/client"
|
||||||
"github.com/tendermint/abci/types"
|
"github.com/tendermint/abci/types"
|
||||||
. "github.com/tendermint/go-common"
|
|
||||||
"github.com/tendermint/go-process"
|
"github.com/tendermint/go-process"
|
||||||
)
|
)
|
||||||
|
|
||||||
//----------------------------------------
|
func startApp(abciApp string) *process.Process {
|
||||||
|
|
||||||
func StartApp(abciApp string) *process.Process {
|
|
||||||
// Start the app
|
// Start the app
|
||||||
//outBuf := NewBufferCloser(nil)
|
//outBuf := NewBufferCloser(nil)
|
||||||
proc, err := process.StartProcess("abci_app",
|
proc, err := process.StartProcess("abci_app",
|
||||||
@ -33,7 +31,7 @@ func StartApp(abciApp string) *process.Process {
|
|||||||
return proc
|
return proc
|
||||||
}
|
}
|
||||||
|
|
||||||
func StartClient(abciType string) abcicli.Client {
|
func startClient(abciType string) abcicli.Client {
|
||||||
// Start client
|
// Start client
|
||||||
client, err := abcicli.NewClient("tcp://127.0.0.1:46658", abciType, true)
|
client, err := abcicli.NewClient("tcp://127.0.0.1:46658", abciType, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -42,51 +40,51 @@ func StartClient(abciType string) abcicli.Client {
|
|||||||
return client
|
return client
|
||||||
}
|
}
|
||||||
|
|
||||||
func SetOption(client abcicli.Client, key, value string) {
|
func setOption(client abcicli.Client, key, value string) {
|
||||||
res := client.SetOptionSync(key, value)
|
res := client.SetOptionSync(key, value)
|
||||||
_, _, log := res.Code, res.Data, res.Log
|
_, _, log := res.Code, res.Data, res.Log
|
||||||
if res.IsErr() {
|
if res.IsErr() {
|
||||||
panic(Fmt("setting %v=%v: \nlog: %v", key, value, log))
|
panic(fmt.Sprintf("setting %v=%v: \nlog: %v", key, value, log))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func Commit(client abcicli.Client, hashExp []byte) {
|
func commit(client abcicli.Client, hashExp []byte) {
|
||||||
res := client.CommitSync()
|
res := client.CommitSync()
|
||||||
_, data, log := res.Code, res.Data, res.Log
|
_, data, log := res.Code, res.Data, res.Log
|
||||||
if res.IsErr() {
|
if res.IsErr() {
|
||||||
panic(Fmt("committing %v\nlog: %v", log))
|
panic(fmt.Sprintf("committing %v\nlog: %v", log))
|
||||||
}
|
}
|
||||||
if !bytes.Equal(res.Data, hashExp) {
|
if !bytes.Equal(res.Data, hashExp) {
|
||||||
panic(Fmt("Commit hash was unexpected. Got %X expected %X",
|
panic(fmt.Sprintf("Commit hash was unexpected. Got %X expected %X",
|
||||||
data, hashExp))
|
data, hashExp))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func DeliverTx(client abcicli.Client, txBytes []byte, codeExp types.CodeType, dataExp []byte) {
|
func deliverTx(client abcicli.Client, txBytes []byte, codeExp types.CodeType, dataExp []byte) {
|
||||||
res := client.DeliverTxSync(txBytes)
|
res := client.DeliverTxSync(txBytes)
|
||||||
code, data, log := res.Code, res.Data, res.Log
|
code, data, log := res.Code, res.Data, res.Log
|
||||||
if code != codeExp {
|
if code != codeExp {
|
||||||
panic(Fmt("DeliverTx response code was unexpected. Got %v expected %v. Log: %v",
|
panic(fmt.Sprintf("DeliverTx response code was unexpected. Got %v expected %v. Log: %v",
|
||||||
code, codeExp, log))
|
code, codeExp, log))
|
||||||
}
|
}
|
||||||
if !bytes.Equal(data, dataExp) {
|
if !bytes.Equal(data, dataExp) {
|
||||||
panic(Fmt("DeliverTx response data was unexpected. Got %X expected %X",
|
panic(fmt.Sprintf("DeliverTx response data was unexpected. Got %X expected %X",
|
||||||
data, dataExp))
|
data, dataExp))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func CheckTx(client abcicli.Client, txBytes []byte, codeExp types.CodeType, dataExp []byte) {
|
func checkTx(client abcicli.Client, txBytes []byte, codeExp types.CodeType, dataExp []byte) {
|
||||||
res := client.CheckTxSync(txBytes)
|
res := client.CheckTxSync(txBytes)
|
||||||
code, data, log := res.Code, res.Data, res.Log
|
code, data, log := res.Code, res.Data, res.Log
|
||||||
if res.IsErr() {
|
if res.IsErr() {
|
||||||
panic(Fmt("checking tx %X: %v\nlog: %v", txBytes, log))
|
panic(fmt.Sprintf("checking tx %X: %v\nlog: %v", txBytes, log))
|
||||||
}
|
}
|
||||||
if code != codeExp {
|
if code != codeExp {
|
||||||
panic(Fmt("CheckTx response code was unexpected. Got %v expected %v. Log: %v",
|
panic(fmt.Sprintf("CheckTx response code was unexpected. Got %v expected %v. Log: %v",
|
||||||
code, codeExp, log))
|
code, codeExp, log))
|
||||||
}
|
}
|
||||||
if !bytes.Equal(data, dataExp) {
|
if !bytes.Equal(data, dataExp) {
|
||||||
panic(Fmt("CheckTx response data was unexpected. Got %X expected %X",
|
panic(fmt.Sprintf("CheckTx response data was unexpected. Got %X expected %X",
|
||||||
data, dataExp))
|
data, dataExp))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,22 +27,22 @@ func testCounter() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("Running %s test with abci=%s\n", abciApp, abciType)
|
fmt.Printf("Running %s test with abci=%s\n", abciApp, abciType)
|
||||||
appProc := StartApp(abciApp)
|
appProc := startApp(abciApp)
|
||||||
defer appProc.StopProcess(true)
|
defer appProc.StopProcess(true)
|
||||||
client := StartClient(abciType)
|
client := startClient(abciType)
|
||||||
defer client.Stop()
|
defer client.Stop()
|
||||||
|
|
||||||
SetOption(client, "serial", "on")
|
setOption(client, "serial", "on")
|
||||||
Commit(client, nil)
|
commit(client, nil)
|
||||||
DeliverTx(client, []byte("abc"), types.CodeType_BadNonce, nil)
|
deliverTx(client, []byte("abc"), types.CodeType_BadNonce, nil)
|
||||||
Commit(client, nil)
|
commit(client, nil)
|
||||||
DeliverTx(client, []byte{0x00}, types.CodeType_OK, nil)
|
deliverTx(client, []byte{0x00}, types.CodeType_OK, nil)
|
||||||
Commit(client, []byte{0, 0, 0, 0, 0, 0, 0, 1})
|
commit(client, []byte{0, 0, 0, 0, 0, 0, 0, 1})
|
||||||
DeliverTx(client, []byte{0x00}, types.CodeType_BadNonce, nil)
|
deliverTx(client, []byte{0x00}, types.CodeType_BadNonce, nil)
|
||||||
DeliverTx(client, []byte{0x01}, types.CodeType_OK, nil)
|
deliverTx(client, []byte{0x01}, types.CodeType_OK, nil)
|
||||||
DeliverTx(client, []byte{0x00, 0x02}, types.CodeType_OK, nil)
|
deliverTx(client, []byte{0x00, 0x02}, types.CodeType_OK, nil)
|
||||||
DeliverTx(client, []byte{0x00, 0x03}, types.CodeType_OK, nil)
|
deliverTx(client, []byte{0x00, 0x03}, types.CodeType_OK, nil)
|
||||||
DeliverTx(client, []byte{0x00, 0x00, 0x04}, types.CodeType_OK, nil)
|
deliverTx(client, []byte{0x00, 0x00, 0x04}, types.CodeType_OK, nil)
|
||||||
DeliverTx(client, []byte{0x00, 0x00, 0x06}, types.CodeType_BadNonce, nil)
|
deliverTx(client, []byte{0x00, 0x00, 0x06}, types.CodeType_BadNonce, nil)
|
||||||
Commit(client, []byte{0, 0, 0, 0, 0, 0, 0, 5})
|
commit(client, []byte{0, 0, 0, 0, 0, 0, 0, 5})
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user