mirror of
https://github.com/fluencelabs/tendermint
synced 2025-07-03 14:41:37 +00:00
index by bytes. add TxID to broadcast_tx responses
This commit is contained in:
@ -18,7 +18,7 @@ func BroadcastTxAsync(tx types.Tx) (*ctypes.ResultBroadcastTx, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("Error broadcasting transaction: %v", err)
|
return nil, fmt.Errorf("Error broadcasting transaction: %v", err)
|
||||||
}
|
}
|
||||||
return &ctypes.ResultBroadcastTx{}, nil
|
return &ctypes.ResultBroadcastTx{TxID: tx.Hash()}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns with the response from CheckTx
|
// Returns with the response from CheckTx
|
||||||
@ -36,6 +36,7 @@ func BroadcastTxSync(tx types.Tx) (*ctypes.ResultBroadcastTx, error) {
|
|||||||
Code: r.Code,
|
Code: r.Code,
|
||||||
Data: r.Data,
|
Data: r.Data,
|
||||||
Log: r.Log,
|
Log: r.Log,
|
||||||
|
TxID: tx.Hash(),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,6 +68,7 @@ func BroadcastTxCommit(tx types.Tx) (*ctypes.ResultBroadcastTxCommit, error) {
|
|||||||
return &ctypes.ResultBroadcastTxCommit{
|
return &ctypes.ResultBroadcastTxCommit{
|
||||||
CheckTx: checkTxR,
|
CheckTx: checkTxR,
|
||||||
DeliverTx: nil,
|
DeliverTx: nil,
|
||||||
|
TxID: tx.Hash(),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,12 +88,14 @@ func BroadcastTxCommit(tx types.Tx) (*ctypes.ResultBroadcastTxCommit, error) {
|
|||||||
return &ctypes.ResultBroadcastTxCommit{
|
return &ctypes.ResultBroadcastTxCommit{
|
||||||
CheckTx: checkTxR,
|
CheckTx: checkTxR,
|
||||||
DeliverTx: deliverTxR,
|
DeliverTx: deliverTxR,
|
||||||
|
TxID: tx.Hash(),
|
||||||
}, nil
|
}, nil
|
||||||
case <-timer.C:
|
case <-timer.C:
|
||||||
log.Error("failed to include tx")
|
log.Error("failed to include tx")
|
||||||
return &ctypes.ResultBroadcastTxCommit{
|
return &ctypes.ResultBroadcastTxCommit{
|
||||||
CheckTx: checkTxR,
|
CheckTx: checkTxR,
|
||||||
DeliverTx: nil,
|
DeliverTx: nil,
|
||||||
|
TxID: tx.Hash(),
|
||||||
}, fmt.Errorf("Timed out waiting for transaction to be included in a block")
|
}, fmt.Errorf("Timed out waiting for transaction to be included in a block")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,12 +1,9 @@
|
|||||||
package core
|
package core
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strings"
|
|
||||||
|
|
||||||
rpc "github.com/tendermint/go-rpc/server"
|
rpc "github.com/tendermint/go-rpc/server"
|
||||||
"github.com/tendermint/go-rpc/types"
|
"github.com/tendermint/go-rpc/types"
|
||||||
ctypes "github.com/tendermint/tendermint/rpc/core/types"
|
ctypes "github.com/tendermint/tendermint/rpc/core/types"
|
||||||
"github.com/tendermint/tendermint/types"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// TODO: better system than "unsafe" prefix
|
// TODO: better system than "unsafe" prefix
|
||||||
@ -22,11 +19,11 @@ var Routes = map[string]*rpc.RPCFunc{
|
|||||||
"genesis": rpc.NewRPCFunc(GenesisResult, ""),
|
"genesis": rpc.NewRPCFunc(GenesisResult, ""),
|
||||||
"block": rpc.NewRPCFunc(BlockResult, "height"),
|
"block": rpc.NewRPCFunc(BlockResult, "height"),
|
||||||
"commit": rpc.NewRPCFunc(CommitResult, "height"),
|
"commit": rpc.NewRPCFunc(CommitResult, "height"),
|
||||||
|
"tx": rpc.NewRPCFunc(TxResult, "hash"),
|
||||||
"validators": rpc.NewRPCFunc(ValidatorsResult, ""),
|
"validators": rpc.NewRPCFunc(ValidatorsResult, ""),
|
||||||
"dump_consensus_state": rpc.NewRPCFunc(DumpConsensusStateResult, ""),
|
"dump_consensus_state": rpc.NewRPCFunc(DumpConsensusStateResult, ""),
|
||||||
"unconfirmed_txs": rpc.NewRPCFunc(UnconfirmedTxsResult, ""),
|
"unconfirmed_txs": rpc.NewRPCFunc(UnconfirmedTxsResult, ""),
|
||||||
"num_unconfirmed_txs": rpc.NewRPCFunc(NumUnconfirmedTxsResult, ""),
|
"num_unconfirmed_txs": rpc.NewRPCFunc(NumUnconfirmedTxsResult, ""),
|
||||||
"tx": rpc.NewRPCFunc(Tx, "hash"),
|
|
||||||
|
|
||||||
// broadcast API
|
// broadcast API
|
||||||
"broadcast_tx_commit": rpc.NewRPCFunc(BroadcastTxCommitResult, "tx"),
|
"broadcast_tx_commit": rpc.NewRPCFunc(BroadcastTxCommitResult, "tx"),
|
||||||
@ -103,13 +100,8 @@ func NumUnconfirmedTxsResult() (ctypes.TMResult, error) {
|
|||||||
// Tx allow user to query the transaction results. `nil` could mean the
|
// Tx allow user to query the transaction results. `nil` could mean the
|
||||||
// transaction is in the mempool, invalidated, or was not send in the first
|
// transaction is in the mempool, invalidated, or was not send in the first
|
||||||
// place.
|
// place.
|
||||||
func Tx(hash string) (ctypes.TMResult, error) {
|
func TxResult(hash []byte) (ctypes.TMResult, error) {
|
||||||
r, err := txIndexer.Tx(strings.ToLower(hash))
|
return Tx(hash)
|
||||||
// nil-pointer interface values are forbidden in go-rpc
|
|
||||||
if r == (*types.TxResult)(nil) {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return r, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BroadcastTxCommitResult(tx []byte) (ctypes.TMResult, error) {
|
func BroadcastTxCommitResult(tx []byte) (ctypes.TMResult, error) {
|
||||||
|
13
rpc/core/tx.go
Normal file
13
rpc/core/tx.go
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
package core
|
||||||
|
|
||||||
|
import (
|
||||||
|
ctypes "github.com/tendermint/tendermint/rpc/core/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Tx(hash []byte) (*ctypes.ResultTx, error) {
|
||||||
|
r, err := txIndexer.Tx(hash)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &ctypes.ResultTx{*r}, nil
|
||||||
|
}
|
@ -67,11 +67,18 @@ type ResultBroadcastTx struct {
|
|||||||
Code abci.CodeType `json:"code"`
|
Code abci.CodeType `json:"code"`
|
||||||
Data []byte `json:"data"`
|
Data []byte `json:"data"`
|
||||||
Log string `json:"log"`
|
Log string `json:"log"`
|
||||||
|
|
||||||
|
TxID []byte `json:"tx_id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ResultBroadcastTxCommit struct {
|
type ResultBroadcastTxCommit struct {
|
||||||
CheckTx *abci.ResponseCheckTx `json:"check_tx"`
|
CheckTx *abci.ResponseCheckTx `json:"check_tx"`
|
||||||
DeliverTx *abci.ResponseDeliverTx `json:"deliver_tx"`
|
DeliverTx *abci.ResponseDeliverTx `json:"deliver_tx"`
|
||||||
|
TxID []byte `json:"tx_id"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type ResultTx struct {
|
||||||
|
types.TxResult
|
||||||
}
|
}
|
||||||
|
|
||||||
type ResultUnconfirmedTxs struct {
|
type ResultUnconfirmedTxs struct {
|
||||||
@ -164,7 +171,7 @@ var _ = wire.RegisterInterface(
|
|||||||
wire.ConcreteType{&ResultDumpConsensusState{}, ResultTypeDumpConsensusState},
|
wire.ConcreteType{&ResultDumpConsensusState{}, ResultTypeDumpConsensusState},
|
||||||
wire.ConcreteType{&ResultBroadcastTx{}, ResultTypeBroadcastTx},
|
wire.ConcreteType{&ResultBroadcastTx{}, ResultTypeBroadcastTx},
|
||||||
wire.ConcreteType{&ResultBroadcastTxCommit{}, ResultTypeBroadcastTxCommit},
|
wire.ConcreteType{&ResultBroadcastTxCommit{}, ResultTypeBroadcastTxCommit},
|
||||||
wire.ConcreteType{&types.TxResult{}, ResultTypeTx},
|
wire.ConcreteType{&ResultTx{}, ResultTypeTx},
|
||||||
wire.ConcreteType{&ResultUnconfirmedTxs{}, ResultTypeUnconfirmedTxs},
|
wire.ConcreteType{&ResultUnconfirmedTxs{}, ResultTypeUnconfirmedTxs},
|
||||||
wire.ConcreteType{&ResultSubscribe{}, ResultTypeSubscribe},
|
wire.ConcreteType{&ResultSubscribe{}, ResultTypeSubscribe},
|
||||||
wire.ConcreteType{&ResultUnsubscribe{}, ResultTypeUnsubscribe},
|
wire.ConcreteType{&ResultUnsubscribe{}, ResultTypeUnsubscribe},
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package state
|
package state
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/hex"
|
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
@ -246,7 +245,7 @@ func (s *State) ApplyBlock(eventCache types.Fireable, proxyAppConn proxy.AppConn
|
|||||||
if r != nil {
|
if r != nil {
|
||||||
tx := block.Txs[i]
|
tx := block.Txs[i]
|
||||||
// dd2e325f79f7e5f77788759d278c1d4b370c842e => {"height":2405, "index":0, ...}
|
// dd2e325f79f7e5f77788759d278c1d4b370c842e => {"height":2405, "index":0, ...}
|
||||||
batch.Index(hex.EncodeToString(tx.Hash()), *r)
|
batch.Index(tx.Hash(), *r)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
s.TxIndexer.Batch(batch)
|
s.TxIndexer.Batch(batch)
|
||||||
|
@ -17,5 +17,5 @@ type Indexer interface {
|
|||||||
|
|
||||||
// Tx returns specified transaction or nil if the transaction is not indexed
|
// Tx returns specified transaction or nil if the transaction is not indexed
|
||||||
// or stored.
|
// or stored.
|
||||||
Tx(hash string) (*types.TxResult, error)
|
Tx(hash []byte) (*types.TxResult, error)
|
||||||
}
|
}
|
||||||
|
@ -18,11 +18,11 @@ func NewBatch() *Batch {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Index adds or updates entry for the given hash.
|
// Index adds or updates entry for the given hash.
|
||||||
func (b *Batch) Index(hash string, result types.TxResult) error {
|
func (b *Batch) Index(hash []byte, result types.TxResult) error {
|
||||||
if hash == "" {
|
if len(hash) == 0 {
|
||||||
return ErrorEmptyHash
|
return ErrorEmptyHash
|
||||||
}
|
}
|
||||||
b.Ops[hash] = result
|
b.Ops[string(hash)] = result
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,12 +22,12 @@ func NewKV(store db.DB) *KV {
|
|||||||
|
|
||||||
// Tx gets transaction from the KV storage and returns it or nil if the
|
// Tx gets transaction from the KV storage and returns it or nil if the
|
||||||
// transaction is not found.
|
// transaction is not found.
|
||||||
func (indexer *KV) Tx(hash string) (*types.TxResult, error) {
|
func (indexer *KV) Tx(hash []byte) (*types.TxResult, error) {
|
||||||
if hash == "" {
|
if len(hash) == 0 {
|
||||||
return nil, ErrorEmptyHash
|
return nil, ErrorEmptyHash
|
||||||
}
|
}
|
||||||
|
|
||||||
rawBytes := indexer.store.Get([]byte(hash))
|
rawBytes := indexer.store.Get(hash)
|
||||||
if rawBytes == nil {
|
if rawBytes == nil {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ func TestKVIndex(t *testing.T) {
|
|||||||
|
|
||||||
tx := types.Tx("HELLO WORLD")
|
tx := types.Tx("HELLO WORLD")
|
||||||
txResult := &types.TxResult{1, 1, abci.ResponseDeliverTx{Data: []byte{0}, Code: abci.CodeType_OK, Log: ""}}
|
txResult := &types.TxResult{1, 1, abci.ResponseDeliverTx{Data: []byte{0}, Code: abci.CodeType_OK, Log: ""}}
|
||||||
hash := string(tx.Hash())
|
hash := tx.Hash()
|
||||||
|
|
||||||
batch := NewBatch()
|
batch := NewBatch()
|
||||||
batch.Index(hash, *txResult)
|
batch.Index(hash, *txResult)
|
||||||
@ -44,7 +44,7 @@ func benchmarkKVIndex(txsCount int, b *testing.B) {
|
|||||||
|
|
||||||
batch := NewBatch()
|
batch := NewBatch()
|
||||||
for i := 0; i < txsCount; i++ {
|
for i := 0; i < txsCount; i++ {
|
||||||
batch.Index(fmt.Sprintf("hash%v", i), *txResult)
|
batch.Index([]byte(fmt.Sprintf("hash%v", i)), *txResult)
|
||||||
}
|
}
|
||||||
|
|
||||||
b.ResetTimer()
|
b.ResetTimer()
|
||||||
|
@ -9,8 +9,8 @@ import (
|
|||||||
type Null struct{}
|
type Null struct{}
|
||||||
|
|
||||||
// Tx panics.
|
// Tx panics.
|
||||||
func (indexer *Null) Tx(hash string) (*types.TxResult, error) {
|
func (indexer *Null) Tx(hash []byte) (*types.TxResult, error) {
|
||||||
return nil, errors.New("Indexing is disabled (set `tx_indexer=kv` in config)")
|
return nil, errors.New(`Indexing is disabled (set 'tx_indexer = "kv"' in config)`)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Batch returns nil.
|
// Batch returns nil.
|
||||||
|
Reference in New Issue
Block a user