testing tx transmission

This commit is contained in:
Jae Kwon 2014-12-31 23:21:47 -08:00
parent 0d075c7592
commit f02ba63412
8 changed files with 30 additions and 24 deletions

View File

@ -11,8 +11,8 @@ var log = log15.New("module", "binary")
func init() {
log.SetHandler(
log15.LvlFilterHandler(
log15.LvlWarn,
//log15.LvlDebug,
//log15.LvlWarn,
log15.LvlDebug,
log15.StreamHandler(os.Stderr, log15.LogfmtFormat()),
),
)

View File

@ -90,7 +90,19 @@ func readReflect(rv reflect.Value, rt reflect.Type, r Unreader, n *int64, err *e
log.Debug("Read reflect", "type", rt)
// First, create a new struct if rv is nil pointer.
// Get typeInfo
typeInfo := GetTypeInfo(rt)
// Custom decoder
if typeInfo.Decoder != nil {
decoded := typeInfo.Decoder(r, n, err)
//decodedRv := reflect.Indirect(reflect.ValueOf(decoded))
//rv.Set(decodedRv)
rv.Set(reflect.ValueOf(decoded))
return
}
// Create a new struct if rv is nil pointer.
if rt.Kind() == reflect.Ptr && rv.IsNil() {
newRv := reflect.New(rt.Elem())
rv.Set(newRv)
@ -103,17 +115,6 @@ func readReflect(rv reflect.Value, rt reflect.Type, r Unreader, n *int64, err *e
rv, rt = rv.Elem(), rt.Elem()
}
// Get typeInfo
typeInfo := GetTypeInfo(rt)
// Custom decoder
if typeInfo.Decoder != nil {
decoded := typeInfo.Decoder(r, n, err)
decodedRv := reflect.Indirect(reflect.ValueOf(decoded))
rv.Set(decodedRv)
return
}
// Read TypeByte prefix
if typeInfo.HasTypeByte {
typeByte := ReadByte(r, n, err)

View File

@ -50,7 +50,7 @@ func NewNode() *Node {
pexReactor := p2p.NewPEXReactor(book)
// Get MempoolReactor
mempool := mempool_.NewMempool(state)
mempool := mempool_.NewMempool(state.Copy())
mempoolReactor := mempool_.NewMempoolReactor(mempool)
// Get ConsensusReactor

View File

@ -119,6 +119,6 @@ func gen_tx() {
}
// Sign
tx.Inputs[0].Signature = srcPrivKey.Sign(binary.BinaryBytes(tx))
tx.Inputs[0].Signature = srcPrivKey.Sign(account_.SignBytes(tx))
fmt.Printf("Signed tx: %X\n", binary.BinaryBytes(tx))
}

View File

@ -96,7 +96,7 @@ func RecoverAndLogHandler(handler http.Handler) http.Handler {
// For the rest,
rww.WriteHeader(http.StatusInternalServerError)
rww.Write([]byte("Internal Server Error"))
log.Error("Panic in HTTP handler", "error", e, "stack", debug.Stack())
log.Error("Panic in HTTP handler", "error", e, "stack", string(debug.Stack()))
}
}

View File

@ -17,10 +17,12 @@ func MempoolHandler(w http.ResponseWriter, r *http.Request) {
}
reader, n := bytes.NewReader(txBytes), new(int64)
tx := block.TxDecoder(reader, n, &err).(block.Tx)
tx_ := block.TxDecoder(reader, n, &err)
if err != nil {
ReturnJSON(API_INVALID_PARAM, Fmt("Invalid tx_bytes: %v", err))
}
// XXX Oops, I need to cast later like this, everywhere.
tx := tx_.(block.Tx)
err = mempoolReactor.BroadcastTx(tx)
if err != nil {
@ -31,6 +33,5 @@ func MempoolHandler(w http.ResponseWriter, r *http.Request) {
}
/*
curl --data 'tx_bytes=0101146070FF17C39B2B0A64CA2BC431328037FA0F476064000000000000000001407D28F5CEE2065FCB2952CA9B99E9F9855E992B0FA5862442F582F2A84C3B3B31154A86D54DD548AFF080697BDC15AF26E68416AA678EF29449BB8D273B73320502206BD490C212E701A2136EEEA04F06FA4F287EE47E2B7A9B5D62EDD84CD6AD975301146070FF17C39B2B0A64CA2BC431328037FA0F47606400000000000000' -H 'content-type: text/plain;' http://127.0.0.1:8888/mempool
tx: 0101146070FF17C39B2B0A64CA2BC431328037FA0F476064000000000000000001407D28F5CEE2065FCB2952CA9B99E9F9855E992B0FA5862442F582F2A84C3B3B31154A86D54DD548AFF080697BDC15AF26E68416AA678EF29449BB8D273B73320502206BD490C212E701A2136EEEA04F06FA4F287EE47E2B7A9B5D62EDD84CD6AD975301146070FF17C39B2B0A64CA2BC431328037FA0F47606400000000000000
curl -H 'content-type: text/plain;' http://127.0.0.1:8888/mempool?tx_bytes=0101146070FF17C39B2B0A64CA2BC431328037FA0F47606400000000000000000140D209A7CD4E2E7C5E4B17815AB93029960AF66D3428DE7B085EBDBACD84A31F58562EFF0AC4EC7151B071DE82417110C94FFEE862A3740624D7A8C1874AFCF50402206BD490C212E701A2136EEEA04F06FA4F287EE47E2B7A9B5D62EDD84CD6AD975301146070FF17C39B2B0A64CA2BC431328037FA0F47FF6400000000000000
*/

View File

@ -117,6 +117,10 @@ func MakeGenesisState(db db_.DB, genDoc *GenesisDoc) *State {
}
}
// IAVLTrees must be persisted before copy operations.
accounts.Save()
validatorInfos.Save()
return &State{
DB: db,
LastBlockHeight: 0,

View File

@ -2,7 +2,7 @@ package state
import (
"bytes"
"encoding/base64"
"encoding/hex"
"sort"
. "github.com/tendermint/tendermint/account"
@ -65,7 +65,7 @@ func RandGenesisState(numAccounts int, randBalance bool, minBalance uint64, numV
for i := 0; i < numAccounts; i++ {
account, privAccount := RandAccount(randBalance, minBalance)
accounts[i] = GenesisAccount{
Address: base64.StdEncoding.EncodeToString(account.Address),
Address: hex.EncodeToString(account.Address),
Amount: account.Balance,
}
privAccounts[i] = privAccount
@ -75,11 +75,11 @@ func RandGenesisState(numAccounts int, randBalance bool, minBalance uint64, numV
for i := 0; i < numValidators; i++ {
valInfo, privVal := RandValidator(randBonded, minBonded)
validators[i] = GenesisValidator{
PubKey: base64.StdEncoding.EncodeToString(BinaryBytes(valInfo.PubKey)),
PubKey: hex.EncodeToString(BinaryBytes(valInfo.PubKey)),
Amount: valInfo.FirstBondAmount,
UnbondTo: []GenesisAccount{
{
Address: base64.StdEncoding.EncodeToString(valInfo.PubKey.Address()),
Address: hex.EncodeToString(valInfo.PubKey.Address()),
Amount: valInfo.FirstBondAmount,
},
},