Skip to content

Commit

Permalink
v3.11.1: prioritize transfer tx in tx pool
Browse files Browse the repository at this point in the history
  • Loading branch information
Ji Qiren committed Dec 15, 2023
1 parent 5920d31 commit 3783fb7
Show file tree
Hide file tree
Showing 7 changed files with 826 additions and 798 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ GO_INSTALL := $(GO) install

PROJECT_NAME := $(shell basename "$(PWD)")
BUILDER_VERSION = 3.11.0
VERSION = 3.11.0
VERSION = 3.11.1
COMMIT = $(shell git rev-parse --short HEAD)
PROJECT = github.com/iost-official/go-iost
DOCKER_IMAGE = iostio/iost-node:$(VERSION)-$(COMMIT)
Expand Down
4 changes: 2 additions & 2 deletions core/txpool/tx_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,11 @@ func (pool *TxPImpl) initBlockTx() {
func (pool *TxPImpl) verifyTx(t *tx.Tx) error {
isSimpleTransfer := len(t.Actions) == 1 && t.Actions[0].Contract == "token.iost"
if isSimpleTransfer {
if pool.pendingTx.Size() > 2*maxCacheTxs {
if pool.pendingTx.Size() > maxCacheTxs {
return ErrCacheFull
}
} else {
if pool.pendingTx.Size() > maxCacheTxs {
if pool.pendingTx.Size() > maxCacheTxs/10 {
return ErrCacheFull
}
}
Expand Down
8 changes: 8 additions & 0 deletions core/txpool/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,14 @@ type SortedTxMap struct {
func compareTx(a, b any) int {
txa := a.(*tx.Tx)
txb := b.(*tx.Tx)
isSimpleTransferA := len(txa.Actions) == 1 && txa.Actions[0].Contract == "token.iost"
isSimpleTransferB := len(txb.Actions) == 1 && txb.Actions[0].Contract == "token.iost"
if isSimpleTransferA && !isSimpleTransferB {
return 1
}
if !isSimpleTransferA && isSimpleTransferB {
return -1
}
if txa.GasRatio == txb.GasRatio && txb.Time == txa.Time {
return bytes.Compare(txa.Hash(), txb.Hash())
}
Expand Down
2 changes: 2 additions & 0 deletions rpc/api_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,15 @@ func NewAPIService(tp txpool.TxPool, chainBase *chainbase.ChainBase, config *com

// GetNodeInfo returns information abount node.
func (as *APIService) GetNodeInfo(context.Context, *rpcpb.EmptyRequest) (*rpcpb.NodeInfoResponse, error) {
pendingTx, _ := as.txpool.PendingTx()
res := &rpcpb.NodeInfoResponse{
BuildTime: global.BuildTime,
GitHash: global.GitHash,
CodeVersion: global.CodeVersion,
Mode: common.Mode(),
Network: &rpcpb.NetworkInfo{},
ServerTime: time.Now().UnixNano(),
TxPoolSize: int64(pendingTx.Size()),
}

p2pNeighbors := as.p2pService.GetAllNeighbors()
Expand Down
1,601 changes: 806 additions & 795 deletions rpc/pb/rpc.pb.go

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions rpc/pb/rpc.proto
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,8 @@ message NodeInfoResponse {
string code_version = 5;
// server time
int64 server_time = 6;
// tx pool size
int64 tx_pool_size = 7;
}

// The message defines transaction amount limit struct.
Expand Down
5 changes: 5 additions & 0 deletions rpc/pb/rpc.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -2209,6 +2209,11 @@
"type": "string",
"format": "int64",
"title": "server time"
},
"txPoolSize": {
"type": "string",
"format": "int64",
"title": "tx pool size"
}
},
"description": "The message containing the node's information."
Expand Down

0 comments on commit 3783fb7

Please sign in to comment.