diff --git a/build/build.go b/build/build.go index 91d78c7..279aeac 100644 --- a/build/build.go +++ b/build/build.go @@ -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) @@ -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() diff --git a/consensus_shard/pbft_all/accountTransfer_module.go b/consensus_shard/pbft_all/accountTransfer_module.go index 4a217d1..6a3ea65 100644 --- a/consensus_shard/pbft_all/accountTransfer_module.go +++ b/consensus_shard/pbft_all/accountTransfer_module.go @@ -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 @@ -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{ diff --git a/consensus_shard/pbft_all/accountTransfermod_Broker.go b/consensus_shard/pbft_all/accountTransfermod_Broker.go index 35bf535..5676907 100644 --- a/consensus_shard/pbft_all/accountTransfermod_Broker.go +++ b/consensus_shard/pbft_all/accountTransfermod_Broker.go @@ -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 @@ -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{ diff --git a/docs/versionUpdate.md b/docs/versionUpdate.md index 346e0f2..68fdcbd 100644 --- a/docs/versionUpdate.md +++ b/docs/versionUpdate.md @@ -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.