Use BlockCache for RPC/mempool and added TxId()

TxId() uses signbytes
This commit is contained in:
Jae Kwon 2015-03-29 18:43:27 -07:00
parent 19a50c1229
commit 5cb57d3eaa
6 changed files with 18 additions and 7 deletions

1
.gitignore vendored
View File

@ -3,3 +3,4 @@
.bak .bak
tendermint tendermint
.DS_Store .DS_Store
rpc/test/.tendermint

View File

@ -34,6 +34,10 @@ func (mem *Mempool) GetState() *sm.State {
return mem.state return mem.state
} }
func (mem *Mempool) GetCache() *sm.BlockCache {
return mem.cache
}
// Apply tx to the state and remember it. // Apply tx to the state and remember it.
func (mem *Mempool) AddTx(tx types.Tx) (err error) { func (mem *Mempool) AddTx(tx types.Tx) (err error) {
mem.mtx.Lock() mem.mtx.Lock()

View File

@ -13,8 +13,8 @@ func GenPrivAccount() (*ResponseGenPrivAccount, error) {
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
func GetAccount(address []byte) (*ResponseGetAccount, error) { func GetAccount(address []byte) (*ResponseGetAccount, error) {
state := consensusState.GetState() cache := mempoolReactor.Mempool.GetCache()
return &ResponseGetAccount{state.GetAccount(address)}, nil return &ResponseGetAccount{cache.GetAccount(address)}, nil
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------

View File

@ -3,7 +3,6 @@ package core
import ( import (
"fmt" "fmt"
. "github.com/tendermint/tendermint/common" . "github.com/tendermint/tendermint/common"
"github.com/tendermint/tendermint/merkle"
"github.com/tendermint/tendermint/state" "github.com/tendermint/tendermint/state"
"github.com/tendermint/tendermint/types" "github.com/tendermint/tendermint/types"
) )
@ -24,7 +23,7 @@ func BroadcastTx(tx types.Tx) (*ResponseBroadcastTx, error) {
return nil, fmt.Errorf("Error broadcasting transaction: %v", err) return nil, fmt.Errorf("Error broadcasting transaction: %v", err)
} }
txHash := merkle.HashFromBinary(tx) txHash := types.TxId(tx)
var createsContract uint8 var createsContract uint8
var contractAddr []byte var contractAddr []byte
// check if creates new contract // check if creates new contract

View File

@ -6,8 +6,8 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"github.com/tendermint/tendermint/binary" "github.com/tendermint/tendermint/binary"
. "github.com/tendermint/tendermint/common"
"github.com/tendermint/tendermint/config" "github.com/tendermint/tendermint/config"
"github.com/tendermint/tendermint/merkle"
"github.com/tendermint/tendermint/rpc" "github.com/tendermint/tendermint/rpc"
"github.com/tendermint/tendermint/rpc/core" "github.com/tendermint/tendermint/rpc/core"
"github.com/tendermint/tendermint/types" "github.com/tendermint/tendermint/types"
@ -161,8 +161,8 @@ func TestJSONBroadcastTx(t *testing.T) {
} }
tx2 := txs[mempoolCount].(*types.SendTx) tx2 := txs[mempoolCount].(*types.SendTx)
mempoolCount += 1 mempoolCount += 1
if bytes.Compare(merkle.HashFromBinary(tx), merkle.HashFromBinary(tx2)) != 0 { if bytes.Compare(types.TxId(tx), types.TxId(tx2)) != 0 {
t.Fatal("inconsistent hashes for mempool tx and sent tx") t.Fatal(Fmt("inconsistent hashes for mempool tx and sent tx: %v vs %v", tx, tx2))
} }
} }

View File

@ -254,3 +254,10 @@ func (tx *DupeoutTx) WriteSignBytes(w io.Writer, n *int64, err *error) {
func (tx *DupeoutTx) String() string { func (tx *DupeoutTx) String() string {
return Fmt("DupeoutTx{%X,%v,%v}", tx.Address, tx.VoteA, tx.VoteB) return Fmt("DupeoutTx{%X,%v,%v}", tx.Address, tx.VoteA, tx.VoteB)
} }
//-----------------------------------------------------------------------------
func TxId(tx Tx) []byte {
signBytes := account.SignBytes(tx)
return binary.BinaryRipemd160(signBytes)
}