Browse Source

more fixes from review

pull/412/head
Ethan Buchman 8 years ago
parent
commit
b6a04a3456
8 changed files with 29 additions and 32 deletions
  1. +14
    -10
      node/node.go
  2. +1
    -1
      rpc/core/types/responses.go
  3. +2
    -2
      rpc/core/types/responses_test.go
  4. +2
    -3
      state/execution.go
  5. +2
    -2
      state/execution_test.go
  6. +4
    -9
      state/txindex/indexer.go
  7. +2
    -2
      state/txindex/kv/kv.go
  8. +2
    -3
      state/txindex/kv/kv_test.go

+ 14
- 10
node/node.go View File

@ -217,7 +217,7 @@ func (n *Node) OnStart() error {
n.sw.AddListener(l) n.sw.AddListener(l)
// Start the switch // Start the switch
n.sw.SetNodeInfo(makeNodeInfo(n.config, n.sw, n.privKey))
n.sw.SetNodeInfo(n.makeNodeInfo())
n.sw.SetNodePrivKey(n.privKey) n.sw.SetNodePrivKey(n.privKey)
_, err := n.sw.Start() _, err := n.sw.Start()
if err != nil { if err != nil {
@ -365,35 +365,39 @@ func (n *Node) ProxyApp() proxy.AppConns {
return n.proxyApp return n.proxyApp
} }
func makeNodeInfo(config cfg.Config, sw *p2p.Switch, privKey crypto.PrivKeyEd25519) *p2p.NodeInfo {
func (n *Node) makeNodeInfo() *p2p.NodeInfo {
txIndexerStatus := "on"
if _, ok := n.txIndexer.(*null.TxIndex); ok {
txIndexerStatus = "off"
}
nodeInfo := &p2p.NodeInfo{ nodeInfo := &p2p.NodeInfo{
PubKey: privKey.PubKey().(crypto.PubKeyEd25519),
Moniker: config.GetString("moniker"),
Network: config.GetString("chain_id"),
PubKey: n.privKey.PubKey().(crypto.PubKeyEd25519),
Moniker: n.config.GetString("moniker"),
Network: n.config.GetString("chain_id"),
Version: version.Version, Version: version.Version,
Other: []string{ Other: []string{
cmn.Fmt("wire_version=%v", wire.Version), cmn.Fmt("wire_version=%v", wire.Version),
cmn.Fmt("p2p_version=%v", p2p.Version), cmn.Fmt("p2p_version=%v", p2p.Version),
cmn.Fmt("consensus_version=%v", consensus.Version), cmn.Fmt("consensus_version=%v", consensus.Version),
cmn.Fmt("rpc_version=%v/%v", rpc.Version, rpccore.Version), cmn.Fmt("rpc_version=%v/%v", rpc.Version, rpccore.Version),
cmn.Fmt("tx_indexer=%v", config.GetString("tx_indexer")),
cmn.Fmt("tx_indexer=%v", txIndexerStatus),
}, },
} }
// include git hash in the nodeInfo if available // include git hash in the nodeInfo if available
if rev, err := cmn.ReadFile(config.GetString("revision_file")); err == nil {
if rev, err := cmn.ReadFile(n.config.GetString("revision_file")); err == nil {
nodeInfo.Other = append(nodeInfo.Other, cmn.Fmt("revision=%v", string(rev))) nodeInfo.Other = append(nodeInfo.Other, cmn.Fmt("revision=%v", string(rev)))
} }
if !sw.IsListening() {
if !n.sw.IsListening() {
return nodeInfo return nodeInfo
} }
p2pListener := sw.Listeners()[0]
p2pListener := n.sw.Listeners()[0]
p2pHost := p2pListener.ExternalAddress().IP.String() p2pHost := p2pListener.ExternalAddress().IP.String()
p2pPort := p2pListener.ExternalAddress().Port p2pPort := p2pListener.ExternalAddress().Port
rpcListenAddr := config.GetString("rpc_laddr")
rpcListenAddr := n.config.GetString("rpc_laddr")
// We assume that the rpcListener has the same ExternalAddress. // We assume that the rpcListener has the same ExternalAddress.
// This is probably true because both P2P and RPC listeners use UPnP, // This is probably true because both P2P and RPC listeners use UPnP,


+ 1
- 1
rpc/core/types/responses.go View File

@ -47,7 +47,7 @@ func (s *ResultStatus) TxIndexEnabled() bool {
for _, s := range s.NodeInfo.Other { for _, s := range s.NodeInfo.Other {
info := strings.Split(s, "=") info := strings.Split(s, "=")
if len(info) == 2 && info[0] == "tx_indexer" { if len(info) == 2 && info[0] == "tx_indexer" {
return info[1] == "kv"
return info[1] == "on"
} }
} }
return false return false


+ 2
- 2
rpc/core/types/responses_test.go View File

@ -27,8 +27,8 @@ func TestStatusIndexer(t *testing.T) {
{false, []string{}}, {false, []string{}},
{false, []string{"a=b"}}, {false, []string{"a=b"}},
{false, []string{"tx_indexeriskv", "some=dood"}}, {false, []string{"tx_indexeriskv", "some=dood"}},
{true, []string{"tx_indexer=kv", "tx_indexer=other"}},
{true, []string{"^(*^(", "tx_indexer=kv", "a=n=b=d="}},
{true, []string{"tx_indexer=on", "tx_indexer=other"}},
{true, []string{"^(*^(", "tx_indexer=on", "a=n=b=d="}},
} }
for _, tc := range cases { for _, tc := range cases {


+ 2
- 3
state/execution.go View File

@ -247,9 +247,8 @@ func (s *State) ApplyBlock(eventCache types.Fireable, proxyAppConn proxy.AppConn
} }
batch := txindex.NewBatch() batch := txindex.NewBatch()
for i, r := range txResults {
tx := block.Txs[i]
batch.Index(tx.Hash(), *r)
for _, r := range txResults {
batch.Add(*r)
} }
s.TxIndexer.AddBatch(batch) s.TxIndexer.AddBatch(batch)


+ 2
- 2
state/execution_test.go View File

@ -49,7 +49,7 @@ func TestApplyBlock(t *testing.T) {
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
// make some bogus txs // make some bogus txs
func txsFunc(blockNum int) (txs []types.Tx) {
func makeTxs(blockNum int) (txs []types.Tx) {
for i := 0; i < nTxsPerBlock; i++ { for i := 0; i < nTxsPerBlock; i++ {
txs = append(txs, types.Tx([]byte{byte(blockNum), byte(i)})) txs = append(txs, types.Tx([]byte{byte(blockNum), byte(i)}))
} }
@ -71,7 +71,7 @@ func makeBlock(num int, state *State) *types.Block {
prevParts := types.PartSetHeader{} prevParts := types.PartSetHeader{}
valHash := state.Validators.Hash() valHash := state.Validators.Hash()
prevBlockID := types.BlockID{prevHash, prevParts} prevBlockID := types.BlockID{prevHash, prevParts}
block, _ := types.MakeBlock(num, chainID, txsFunc(num), new(types.Commit),
block, _ := types.MakeBlock(num, chainID, makeTxs(num), new(types.Commit),
prevBlockID, valHash, state.AppHash, testPartSize) prevBlockID, valHash, state.AppHash, testPartSize)
return block return block
} }


+ 4
- 9
state/txindex/indexer.go View File

@ -29,22 +29,17 @@ type TxIndexer interface {
// perform operations on a batch from a single thread at a time. Once batch // perform operations on a batch from a single thread at a time. Once batch
// execution has started, you may not modify it. // execution has started, you may not modify it.
type Batch struct { type Batch struct {
Ops map[string]types.TxResult
Ops []types.TxResult
} }
// NewBatch creates a new Batch. // NewBatch creates a new Batch.
func NewBatch() *Batch { func NewBatch() *Batch {
return &Batch{
Ops: make(map[string]types.TxResult),
}
return &Batch{}
} }
// Index adds or updates entry for the given hash. // Index adds or updates entry for the given hash.
func (b *Batch) Index(hash []byte, result types.TxResult) error {
if len(hash) == 0 {
return ErrorEmptyHash
}
b.Ops[string(hash)] = result
func (b *Batch) Add(result types.TxResult) error {
b.Ops = append(b.Ops, result)
return nil return nil
} }


+ 2
- 2
state/txindex/kv/kv.go View File

@ -47,9 +47,9 @@ func (txi *TxIndex) Get(hash []byte) (*types.TxResult, error) {
// Batch writes a batch of transactions into the TxIndex storage. // Batch writes a batch of transactions into the TxIndex storage.
func (txi *TxIndex) AddBatch(b *txindex.Batch) error { func (txi *TxIndex) AddBatch(b *txindex.Batch) error {
storeBatch := txi.store.NewBatch() storeBatch := txi.store.NewBatch()
for hash, result := range b.Ops {
for _, result := range b.Ops {
rawBytes := wire.BinaryBytes(&result) rawBytes := wire.BinaryBytes(&result)
storeBatch.Set([]byte(hash), rawBytes)
storeBatch.Set(result.Tx.Hash(), rawBytes)
} }
storeBatch.Write() storeBatch.Write()
return nil return nil


+ 2
- 3
state/txindex/kv/kv_test.go View File

@ -1,7 +1,6 @@
package kv package kv
import ( import (
"fmt"
"io/ioutil" "io/ioutil"
"os" "os"
"testing" "testing"
@ -22,7 +21,7 @@ func TestTxIndex(t *testing.T) {
hash := tx.Hash() hash := tx.Hash()
batch := txindex.NewBatch() batch := txindex.NewBatch()
batch.Index(hash, *txResult)
batch.Add(*txResult)
err := indexer.AddBatch(batch) err := indexer.AddBatch(batch)
require.Nil(t, err) require.Nil(t, err)
@ -46,7 +45,7 @@ func benchmarkTxIndex(txsCount int, b *testing.B) {
batch := txindex.NewBatch() batch := txindex.NewBatch()
for i := 0; i < txsCount; i++ { for i := 0; i < txsCount; i++ {
batch.Index([]byte(fmt.Sprintf("hash%v", i)), *txResult)
batch.Add(*txResult)
} }
b.ResetTimer() b.ResetTimer()


Loading…
Cancel
Save