diff --git a/binary/log.go b/binary/log.go index cc6c6372..9eacec2a 100644 --- a/binary/log.go +++ b/binary/log.go @@ -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()), ), ) diff --git a/binary/reflect.go b/binary/reflect.go index e2982ea0..f93d5d81 100644 --- a/binary/reflect.go +++ b/binary/reflect.go @@ -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) diff --git a/cmd/daemon.go b/cmd/daemon.go index 4246006f..e2359dc7 100644 --- a/cmd/daemon.go +++ b/cmd/daemon.go @@ -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 diff --git a/cmd/gen_tx.go b/cmd/gen_tx.go index cfc2e219..a99f44c8 100644 --- a/cmd/gen_tx.go +++ b/cmd/gen_tx.go @@ -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)) } diff --git a/rpc/http_handler.go b/rpc/http_handler.go index 25adbc11..ba25e5a7 100644 --- a/rpc/http_handler.go +++ b/rpc/http_handler.go @@ -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())) } } diff --git a/rpc/mempool.go b/rpc/mempool.go index 6b6ce6c8..82d0d5ff 100644 --- a/rpc/mempool.go +++ b/rpc/mempool.go @@ -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 */ diff --git a/state/genesis.go b/state/genesis.go index cadc1a69..aac4d0ca 100644 --- a/state/genesis.go +++ b/state/genesis.go @@ -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, diff --git a/state/test.go b/state/test.go index 2994082d..8f9ea847 100644 --- a/state/test.go +++ b/state/test.go @@ -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, }, },