Skip to content

Commit

Permalink
account transfer algorithm update
Browse files Browse the repository at this point in the history
  • Loading branch information
iiinotlll committed Jul 21, 2023
1 parent 3a86bcd commit e2937e1
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 20 deletions.
3 changes: 1 addition & 2 deletions build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func initConfig(nid, nnm, sid, snm uint64) *params.ChainConfig {
params.IPmap_nodeTable[i] = make(map[uint64]string)
}
for j := uint64(0); j < nnm; j++ {
params.IPmap_nodeTable[i][j] = "127.0.0.1:" + strconv.Itoa(8800+int(i)*100+int(j))
params.IPmap_nodeTable[i][j] = "127.0.0.1:" + strconv.Itoa(28800+int(i)*100+int(j))
}
}
params.IPmap_nodeTable[params.DeciderShard] = make(map[uint64]string)
Expand Down Expand Up @@ -53,7 +53,6 @@ func BuildSupervisor(nnm, snm, mod uint64) {

func BuildNewPbftNode(nid, nnm, sid, snm, mod uint64) {
worker := pbft_all.NewPbftNode(sid, nid, initConfig(nid, nnm, sid, snm), params.CommitteeMethod[mod])
time.Sleep(5 * time.Second)
if nid == 0 {
go worker.Propose()
worker.TcpListen()
Expand Down
14 changes: 6 additions & 8 deletions consensus_shard/pbft_all/accountTransfer_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,9 @@ func (cphm *CLPAPbftInsideExtraHandleMod) sendAccounts_and_Txs() {
}
// fetch transactions to it, after the transactions is fetched, delete it in the pool
txSend := make([]*core.Transaction, 0)
head := 0
tail := len(cphm.pbftNode.CurChain.Txpool.TxQueue)
for head < tail {
ptx := cphm.pbftNode.CurChain.Txpool.TxQueue[head]
firstPtr := 0
for secondPtr := 0; secondPtr < len(cphm.pbftNode.CurChain.Txpool.TxQueue); secondPtr++ {
ptx := cphm.pbftNode.CurChain.Txpool.TxQueue[secondPtr]
// if this is a normal transaction or ctx1 before re-sharding && the addr is correspond
_, ok1 := addrSet[ptx.Sender]
condition1 := ok1 && !ptx.Relayed
Expand All @@ -96,13 +95,12 @@ func (cphm *CLPAPbftInsideExtraHandleMod) sendAccounts_and_Txs() {
condition2 := ok2 && ptx.Relayed
if condition1 || condition2 {
txSend = append(txSend, ptx)
tail--
cphm.pbftNode.CurChain.Txpool.TxQueue[head] = cphm.pbftNode.CurChain.Txpool.TxQueue[tail]
} else {
head++
cphm.pbftNode.CurChain.Txpool.TxQueue[firstPtr] = ptx
firstPtr++
}
}
cphm.pbftNode.CurChain.Txpool.TxQueue = cphm.pbftNode.CurChain.Txpool.TxQueue[:tail]
cphm.pbftNode.CurChain.Txpool.TxQueue = cphm.pbftNode.CurChain.Txpool.TxQueue[:firstPtr]

cphm.pbftNode.pl.Plog.Printf("The txSend to shard %d is generated \n", i)
ast := message.AccountStateAndTx{
Expand Down
17 changes: 7 additions & 10 deletions consensus_shard/pbft_all/accountTransfermod_Broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,9 @@ func (cphm *CLPAPbftInsideExtraHandleMod_forBroker) sendAccounts_and_Txs() {
}
// fetch transactions to it, after the transactions is fetched, delete it in the pool
txSend := make([]*core.Transaction, 0)
head := 0
tail := len(cphm.pbftNode.CurChain.Txpool.TxQueue)
for head < tail {
ptx := cphm.pbftNode.CurChain.Txpool.TxQueue[head]
firstPtr := 0
for secondPtr := 0; secondPtr < len(cphm.pbftNode.CurChain.Txpool.TxQueue); secondPtr++ {
ptx := cphm.pbftNode.CurChain.Txpool.TxQueue[secondPtr]
// whether should be transfer or not
beSend := false
beRemoved := false
Expand Down Expand Up @@ -119,14 +118,12 @@ func (cphm *CLPAPbftInsideExtraHandleMod_forBroker) sendAccounts_and_Txs() {
if beSend {
txSend = append(txSend, ptx)
}
if beRemoved {
tail--
cphm.pbftNode.CurChain.Txpool.TxQueue[head] = cphm.pbftNode.CurChain.Txpool.TxQueue[tail]
} else {
head++
if !beRemoved {
cphm.pbftNode.CurChain.Txpool.TxQueue[firstPtr] = cphm.pbftNode.CurChain.Txpool.TxQueue[secondPtr]
firstPtr++
}
}
cphm.pbftNode.CurChain.Txpool.TxQueue = cphm.pbftNode.CurChain.Txpool.TxQueue[:tail]
cphm.pbftNode.CurChain.Txpool.TxQueue = cphm.pbftNode.CurChain.Txpool.TxQueue[:firstPtr]

cphm.pbftNode.pl.Plog.Printf("The txSend to shard %d is generated \n", i)
ast := message.AccountStateAndTx{
Expand Down
5 changes: 5 additions & 0 deletions docs/versionUpdate.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Version Updates

## 2023/07/21
**Problem**: The account transferring led to the slight disorganization of txpool.
- **Reason**: The algorithm saved the cost, but mixed up the txpool.
- **Solution**: We rewrite the algorithm, so that it can keep the order of txpool with a small cost.

## 2023/07/18
**Problem**: The tcp connection will report err if the number of shards or nodes is too large.
- **Reason**: The tcp connection is implemented as a *short connection*, which results in too many simultaneous connections due to tcp's wait_close time delaying the closing of the tcp connection.
Expand Down

0 comments on commit e2937e1

Please sign in to comment.