mirror of
https://gitee.com/BTAJL/repchain.git
synced 2024-12-04 12:48:32 +08:00
repchain2.0-update92:检查到节点交易池空时,建立固定延时发送请求的定时器;该定时器在接收到交易时自动关闭。
This commit is contained in:
parent
5f78895c12
commit
afb6b95599
@ -65,7 +65,6 @@ class TransactionChecker (moduleName: String) extends ModuleBase(moduleName){
|
||||
}
|
||||
|
||||
private def addTransToCache(t: Transaction) = {
|
||||
if(!pe.getRepChainContext.getTransactionPool.isExistInCache(t.id)){
|
||||
//交易池中不存在的交易才检查
|
||||
val checkedTransactionResult = checkTransaction(t, dataaccess)
|
||||
//签名验证成功
|
||||
@ -78,9 +77,8 @@ class TransactionChecker (moduleName: String) extends ModuleBase(moduleName){
|
||||
if (poolIsEmpty)//加入交易之前交易池为空,发送抽签消息
|
||||
pe.getActorRef(CFRDActorType.ActorType.voter) ! VoteOfBlocker
|
||||
}else if(!checkedTransactionResult.result){
|
||||
RepLogger.error(RepLogger.System_Logger,this.getLogMsgPrefix(s"${pe.getSysTag} check Transaction error,txid=${t.id}"))
|
||||
RepLogger.error(RepLogger.System_Logger,this.getLogMsgPrefix(s"${pe.getSysTag} check Transaction error,txid=${t.id},msg=${checkedTransactionResult.msg}"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override def receive = {
|
||||
|
@ -57,15 +57,18 @@ class VoterOfCFRD(moduleName: String) extends IVoter(moduleName: String) {
|
||||
private def checkZeroScheduler: Unit = {
|
||||
if (!checkTranNum) {
|
||||
if (schedulerOfZero == null) {
|
||||
this.schedulerOfZero = scheduler.scheduleOnce(15.second, self, VoterOfCFRD.CheckZero)
|
||||
this.schedulerOfZero = scheduler.scheduleWithFixedDelay(15.second,15.second, self, VoterOfCFRD.CheckZero)
|
||||
RepLogger.trace(RepLogger.Vote_Logger, this.getLogMsgPrefix(s"sysname=${pe.getSysTag}," +
|
||||
s"startup scheduler" + "~" + selfAddr))
|
||||
}
|
||||
RepLogger.trace(RepLogger.Vote_Logger, this.getLogMsgPrefix(s"sysname=${pe.getSysTag}," +
|
||||
s"startup scheduler" + "~" + selfAddr))
|
||||
} else {
|
||||
if (schedulerOfZero != null) schedulerOfZero.cancel()
|
||||
this.schedulerOfZero = null
|
||||
RepLogger.trace(RepLogger.Vote_Logger, this.getLogMsgPrefix(s"sysname=${pe.getSysTag}," +
|
||||
s"delete scheduler" + "~" + selfAddr))
|
||||
if (schedulerOfZero != null) {
|
||||
schedulerOfZero.cancel()
|
||||
this.schedulerOfZero = null
|
||||
RepLogger.trace(RepLogger.Vote_Logger, this.getLogMsgPrefix(s"sysname=${pe.getSysTag}," +
|
||||
s"delete scheduler" + "~" + selfAddr))
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -185,15 +188,15 @@ class VoterOfCFRD(moduleName: String) extends IVoter(moduleName: String) {
|
||||
|
||||
private def recvZeroTransactionHandle(zt: RequestWithZeroTransaction): Unit = {
|
||||
RepLogger.trace(RepLogger.Vote_Logger, this.getLogMsgPrefix(s"sysname=${pe.getSysTag}," +
|
||||
s"recv RequestWithZeroTransaction,height=${zt.height},systemName=${zt.systemName}" + "~" + selfAddr))
|
||||
s"recv RequestWithZeroTransaction,height=${zt.height},requester=${zt.systemName}" + "~" + selfAddr))
|
||||
if (new ConsensusCondition(pe.getRepChainContext).CheckWorkConditionOfSystem(pe.getRepChainContext.getNodeMgr.getStableNodes.size)) {
|
||||
if (!pe.isSynching && checkTranNum) {
|
||||
RepLogger.trace(RepLogger.Vote_Logger, this.getLogMsgPrefix(s"sysname=${pe.getSysTag}," +
|
||||
s"recv RequestWithZeroTransaction,broadcast transaction" + "~" + selfAddr))
|
||||
s"recv RequestWithZeroTransaction,broadcast transaction,requester=${zt.systemName}" + "~" + selfAddr))
|
||||
val t = pe.getRepChainContext.getTransactionPool.getRandomTransaction
|
||||
if (t != null) {
|
||||
RepLogger.trace(RepLogger.Vote_Logger, this.getLogMsgPrefix(s"sysname=${pe.getSysTag}," +
|
||||
s"recv RequestWithZeroTransaction,get transaction ,broadcast transaction" + "~" + selfAddr))
|
||||
s"recv RequestWithZeroTransaction,get transaction ,broadcast transaction,tid=${t.id},requester=${zt.systemName}" + "~" + selfAddr))
|
||||
mediator ! Publish(Topic.Transaction, t)
|
||||
}
|
||||
}
|
||||
|
@ -247,8 +247,8 @@ class PoolOfTransaction(ctx:RepChainSystemContext) {
|
||||
}
|
||||
|
||||
def getRandomTransaction:Transaction={
|
||||
val keys = this.transactionCaches.keySet().toArray
|
||||
val num = Random.nextInt() % keys.length
|
||||
val keys = this.transactionCaches.keySet().toArray()
|
||||
val num = math.abs(Random.nextInt()) % keys.length
|
||||
val id : String = keys(num).asInstanceOf[String]
|
||||
val t = getTransaction(id)
|
||||
t
|
||||
|
Loading…
Reference in New Issue
Block a user