1.修改背书信息的排序方法,在背书数组中第一个背书签名为当前块的出块人签名,因此改背书签名的时间就可以确认为出块时间。

2.增加一个test类,手工修改某个worldstate的value。
This commit is contained in:
wuwei1972 2019-09-04 16:45:24 +08:00
parent cb04a2dd0a
commit ac8088b918
4 changed files with 83 additions and 10 deletions

View File

@ -99,7 +99,7 @@ class ConfirmOfBlock(moduleName: String) extends ModuleBase(moduleName) {
if (asyncVerifyEndorses(block)) {
RepLogger.trace(RepLogger.Consensus_Logger, this.getLogMsgPrefix(s"confirm verify endorsement end,height=${block.height}"))
//背书人的签名一致
if (BlockVerify.VerifyEndorserSorted(block.endorsements.toArray[Signature]) == 1 || (block.height==1 && pe.getCurrentBlockHash == "" && block.previousBlockHash.isEmpty())) {
if (BlockVerify.verifySort(block.endorsements.toArray[Signature]) == 1 || (block.height==1 && pe.getCurrentBlockHash == "" && block.previousBlockHash.isEmpty())) {
//背书信息排序正确
RepLogger.trace(RepLogger.Consensus_Logger, this.getLogMsgPrefix( s"confirm verify endorsement sort,height=${block.height}"))
pe.getBlockCacheMgr.addToCache(BlockRestore(block, SourceOfBlock.CONFIRMED_BLOCK, actRefOfBlock))

View File

@ -91,7 +91,7 @@ class EndorseCollector(moduleName: String) extends ModuleBase(moduleName) {
this.block = BlockHelp.AddEndorsementToBlock(this.block, f._2)
})
var consensus = this.block.endorsements.toArray[Signature]
BlockVerify.sort(consensus)
consensus=BlockVerify.sort(consensus)
RepLogger.trace(RepLogger.Consensus_Logger, this.getLogMsgPrefix("collectioner endorsement sort"))
this.block = this.block.withEndorsements(consensus)
RepTimeTracer.setEndTime(pe.getSysTag, "Endorsement", System.currentTimeMillis(),this.block.height,this.block.transactions.size)

View File

@ -154,19 +154,20 @@ object BlockVerify {
/****************************检查背书是否完成结束**********************************************************/
/****************************验证背书信息是否排序的操作开始**********************************************************/
def VerifyEndorserSorted(srclist: Array[Signature]): Int = {
/*def VerifyEndorserSorted(srclist: Array[Signature],startIdx:Int): Int = {
var b: Int = 0
if (srclist == null || srclist.length < 2) {
if (srclist == null || srclist.length < 3) {
println(s"VerifyEndorserSorted~~~~~~~~${b}")
b
} else {
if (IdTool.getSigner4String(srclist(0).getCertId) < IdTool.getSigner4String(srclist(1).getCertId)) { //升序
if (IdTool.getSigner4String(srclist(startIdx).getCertId) < IdTool.getSigner4String(srclist(startIdx+1).getCertId)) { //升序
b = 1
} else { //降序
b = -1
}
breakable(
for (i <- 1 until srclist.length ) {
for (i <- startIdx until srclist.length ) {
if (b == 1 && IdTool.getSigner4String(srclist(i).getCertId) < IdTool.getSigner4String(srclist(i - 1).getCertId)) {
b = 0
break
@ -178,8 +179,9 @@ object BlockVerify {
}
})
}
println(s"VerifyEndorserSorted===========${b}")
b
}
}*/
def VerifyTransactionSorted(srclist: Array[Transaction]): Int = {
var b: Int = 0
@ -208,7 +210,7 @@ object BlockVerify {
b
}
def sort(src: Array[Signature]){
/*def sort(src: Array[Signature],startIdx:Int){
def swap(i:Integer, j:Integer){
val t = src(i)
@ -231,7 +233,39 @@ object BlockVerify {
if(l < j) sortSub(l, j)
if(j < r) sortSub(i, r)
}
sortSub(0, src.length - 1)
}
val a = src.slice(1, src.length)
val b = a.sortWith((l,r)=>IdTool.getSigner4String(l.getCertId)<IdTool.getSigner4String(r.getCertId))
src.patch(1, b, src.length-1)
//sortSub(startIdx, src.length - 1)
} */
def sort(src: Array[Signature]):Array[Signature]={
if(src.length > 1){
val a = src.slice(1, src.length)
val b = a.sortWith((l,r)=>IdTool.getSigner4String(l.getCertId)<IdTool.getSigner4String(r.getCertId))
src.patch(1, b, src.length-1)
}else{
src
}
}
def verifySort(srclist: Array[Signature]):Int={
var b: Int = 1
if(srclist != null && srclist.length > 1){
val as = sort(srclist)
breakable(
for (i <- 0 until srclist.length ) {
if(IdTool.getSigner4String(srclist(i).getCertId) != IdTool.getSigner4String(as(i).getCertId)){
b = 0
break
}
}
)
b
}else{
b = 0
b
}
}
/****************************验证背书信息是否排序的操作结束**********************************************************/
}

View File

@ -0,0 +1,39 @@
package rep.storage.test
import rep.storage.ImpDataAccess
import org.json4s.{ DefaultFormats, jackson }
import org.json4s.native.Serialization.{ write, writePretty }
import rep.protos.peer.CertId
import rep.protos.peer.Signature
import java.util.Date
import rep.crypto.Sha256
import scala.collection.mutable
import rep.storage.util.pathUtil
import scala.math._
import java.io.File;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
//import scala.collection.immutable._
import java.nio.ByteBuffer
import rep.storage.util.pathUtil
import scalapb.json4s.JsonFormat
import org.json4s.{DefaultFormats, Formats, jackson}
import org.json4s.jackson.JsonMethods._
import org.json4s.DefaultFormats._
import scala.collection.mutable.{ArrayBuffer,LinkedHashMap}
import rep.utils.SerializeUtils.serialise
import _root_.com.google.protobuf.ByteString
object modifyWorldState extends App {
val da1 = ImpDataAccess.GetDataAccess("121000005l35120456.node1")
val key = ""
val value = 3
da1.Put(key, serialise(value))
}