block module -> import as blk

This commit is contained in:
Jae Kwon
2015-01-15 22:43:15 -08:00
parent 135894ea88
commit 0a6c28c2da
22 changed files with 323 additions and 323 deletions
+8 -8
View File
@@ -12,14 +12,14 @@ import (
"sync"
"github.com/tendermint/tendermint/binary"
"github.com/tendermint/tendermint/block"
blk "github.com/tendermint/tendermint/block"
sm "github.com/tendermint/tendermint/state"
)
type Mempool struct {
mtx sync.Mutex
state *sm.State
txs []block.Tx
txs []blk.Tx
}
func NewMempool(state *sm.State) *Mempool {
@@ -29,7 +29,7 @@ func NewMempool(state *sm.State) *Mempool {
}
// Apply tx to the state and remember it.
func (mem *Mempool) AddTx(tx block.Tx) (err error) {
func (mem *Mempool) AddTx(tx blk.Tx) (err error) {
mem.mtx.Lock()
defer mem.mtx.Unlock()
err = mem.state.ExecTx(tx)
@@ -43,7 +43,7 @@ func (mem *Mempool) AddTx(tx block.Tx) (err error) {
}
}
func (mem *Mempool) GetProposalTxs() []block.Tx {
func (mem *Mempool) GetProposalTxs() []blk.Tx {
mem.mtx.Lock()
defer mem.mtx.Unlock()
log.Debug("GetProposalTxs:", "txs", mem.txs)
@@ -54,20 +54,20 @@ func (mem *Mempool) GetProposalTxs() []block.Tx {
// "state" is the result of state.AppendBlock("block").
// Txs that are present in "block" are discarded from mempool.
// Txs that have become invalid in the new "state" are also discarded.
func (mem *Mempool) ResetForBlockAndState(block_ *block.Block, state *sm.State) {
func (mem *Mempool) ResetForBlockAndState(block *blk.Block, state *sm.State) {
mem.mtx.Lock()
defer mem.mtx.Unlock()
mem.state = state.Copy()
// First, create a lookup map of txns in new block.
blockTxsMap := make(map[string]struct{})
for _, tx := range block_.Data.Txs {
for _, tx := range block.Data.Txs {
txHash := binary.BinarySha256(tx)
blockTxsMap[string(txHash)] = struct{}{}
}
// Next, filter all txs from mem.txs that are in blockTxsMap
txs := []block.Tx{}
txs := []blk.Tx{}
for _, tx := range mem.txs {
txHash := binary.BinarySha256(tx)
if _, ok := blockTxsMap[string(txHash)]; ok {
@@ -80,7 +80,7 @@ func (mem *Mempool) ResetForBlockAndState(block_ *block.Block, state *sm.State)
}
// Next, filter all txs that aren't valid given new state.
validTxs := []block.Tx{}
validTxs := []blk.Tx{}
for _, tx := range txs {
err := mem.state.ExecTx(tx)
if err == nil {
+3 -3
View File
@@ -6,7 +6,7 @@ import (
"sync/atomic"
"github.com/tendermint/tendermint/binary"
"github.com/tendermint/tendermint/block"
blk "github.com/tendermint/tendermint/block"
"github.com/tendermint/tendermint/p2p"
)
@@ -101,7 +101,7 @@ func (memR *MempoolReactor) Receive(chId byte, src *p2p.Peer, msgBytes []byte) {
}
}
func (memR *MempoolReactor) BroadcastTx(tx block.Tx) error {
func (memR *MempoolReactor) BroadcastTx(tx blk.Tx) error {
err := memR.Mempool.AddTx(tx)
if err != nil {
return err
@@ -136,7 +136,7 @@ func DecodeMessage(bz []byte) (msgType byte, msg interface{}, err error) {
//-------------------------------------
type TxMessage struct {
Tx block.Tx
Tx blk.Tx
}
func (m *TxMessage) TypeByte() byte { return msgTypeTx }