mirror of
https://github.com/tendermint/tendermint.git
synced 2026-09-20 23:14:37 +00:00
Dot import -> named import
Changed modulename_ to short module names Also removed Unreader, replaced with PrefixdReader in select locations
This commit is contained in:
+14
-14
@@ -11,25 +11,25 @@ package mempool
|
||||
import (
|
||||
"sync"
|
||||
|
||||
. "github.com/tendermint/tendermint/binary"
|
||||
. "github.com/tendermint/tendermint/block"
|
||||
"github.com/tendermint/tendermint/state"
|
||||
"github.com/tendermint/tendermint/binary"
|
||||
"github.com/tendermint/tendermint/block"
|
||||
sm "github.com/tendermint/tendermint/state"
|
||||
)
|
||||
|
||||
type Mempool struct {
|
||||
mtx sync.Mutex
|
||||
state *state.State
|
||||
txs []Tx
|
||||
state *sm.State
|
||||
txs []block.Tx
|
||||
}
|
||||
|
||||
func NewMempool(state *state.State) *Mempool {
|
||||
func NewMempool(state *sm.State) *Mempool {
|
||||
return &Mempool{
|
||||
state: state,
|
||||
}
|
||||
}
|
||||
|
||||
// Apply tx to the state and remember it.
|
||||
func (mem *Mempool) AddTx(tx Tx) (err error) {
|
||||
func (mem *Mempool) AddTx(tx block.Tx) (err error) {
|
||||
mem.mtx.Lock()
|
||||
defer mem.mtx.Unlock()
|
||||
err = mem.state.ExecTx(tx)
|
||||
@@ -43,7 +43,7 @@ func (mem *Mempool) AddTx(tx Tx) (err error) {
|
||||
}
|
||||
}
|
||||
|
||||
func (mem *Mempool) GetProposalTxs() []Tx {
|
||||
func (mem *Mempool) GetProposalTxs() []block.Tx {
|
||||
mem.mtx.Lock()
|
||||
defer mem.mtx.Unlock()
|
||||
log.Debug("GetProposalTxs:", "txs", mem.txs)
|
||||
@@ -54,22 +54,22 @@ func (mem *Mempool) GetProposalTxs() []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, state *state.State) {
|
||||
func (mem *Mempool) ResetForBlockAndState(block_ *block.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 {
|
||||
txHash := BinarySha256(tx)
|
||||
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 := []Tx{}
|
||||
txs := []block.Tx{}
|
||||
for _, tx := range mem.txs {
|
||||
txHash := BinarySha256(tx)
|
||||
txHash := binary.BinarySha256(tx)
|
||||
if _, ok := blockTxsMap[string(txHash)]; ok {
|
||||
log.Debug("Filter out, already committed", "tx", tx, "txHash", txHash)
|
||||
continue
|
||||
@@ -80,7 +80,7 @@ func (mem *Mempool) ResetForBlockAndState(block *Block, state *state.State) {
|
||||
}
|
||||
|
||||
// Next, filter all txs that aren't valid given new state.
|
||||
validTxs := []Tx{}
|
||||
validTxs := []block.Tx{}
|
||||
for _, tx := range txs {
|
||||
err := mem.state.ExecTx(tx)
|
||||
if err == nil {
|
||||
|
||||
+5
-5
@@ -5,8 +5,8 @@ import (
|
||||
"fmt"
|
||||
"sync/atomic"
|
||||
|
||||
. "github.com/tendermint/tendermint/binary"
|
||||
. "github.com/tendermint/tendermint/block"
|
||||
"github.com/tendermint/tendermint/binary"
|
||||
"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 Tx) error {
|
||||
func (memR *MempoolReactor) BroadcastTx(tx block.Tx) error {
|
||||
err := memR.Mempool.AddTx(tx)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -126,7 +126,7 @@ func DecodeMessage(bz []byte) (msgType byte, msg interface{}, err error) {
|
||||
r := bytes.NewReader(bz)
|
||||
switch msgType {
|
||||
case msgTypeTx:
|
||||
msg = ReadBinary(&TxMessage{}, r, n, &err)
|
||||
msg = binary.ReadBinary(&TxMessage{}, r, n, &err)
|
||||
default:
|
||||
msg = nil
|
||||
}
|
||||
@@ -136,7 +136,7 @@ func DecodeMessage(bz []byte) (msgType byte, msg interface{}, err error) {
|
||||
//-------------------------------------
|
||||
|
||||
type TxMessage struct {
|
||||
Tx Tx
|
||||
Tx block.Tx
|
||||
}
|
||||
|
||||
func (m *TxMessage) TypeByte() byte { return msgTypeTx }
|
||||
|
||||
Reference in New Issue
Block a user