Skip to content

Commit cc1c40f

Browse files
authored
Merge pull request #2843 from tronprotocol/Hotfix/add_blockCap_hasWitnessSignature
add hasWitnessSignature for BlockCapsule
2 parents 1ef144e + d2a32d5 commit cc1c40f

File tree

4 files changed

+18
-4
lines changed

4 files changed

+18
-4
lines changed

src/main/java/org/tron/common/runtime/RuntimeImpl.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ private double getCpuLimitInUsRatio() {
338338
if (ExecutorType.ET_NORMAL_TYPE == executorType) {
339339
// self witness generates block
340340
if (this.blockCap != null && blockCap.generatedByMyself &&
341-
this.blockCap.getInstance().getBlockHeader().getWitnessSignature().isEmpty()) {
341+
!this.blockCap.hasWitnessSignature()) {
342342
cpuLimitRatio = 1.0;
343343
} else {
344344
// self witness or other witness or fullnode verifies block
@@ -602,7 +602,8 @@ public void go() {
602602
try {
603603
if (vm != null) {
604604
TransactionCapsule trxCap = new TransactionCapsule(trx);
605-
if (null != blockCap && blockCap.generatedByMyself && null != trxCap.getContractRet()
605+
if (null != blockCap && blockCap.generatedByMyself
606+
&& blockCap.hasWitnessSignature() && null != trxCap.getContractRet()
606607
&& contractResult.OUT_OF_TIME == trxCap.getContractRet()) {
607608
result = program.getResult();
608609
program.spendAllEnergy();

src/main/java/org/tron/core/capsule/BlockCapsule.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,10 @@ public long getTimeStamp() {
344344
return this.block.getBlockHeader().getRawData().getTimestamp();
345345
}
346346

347+
public boolean hasWitnessSignature() {
348+
return !getInstance().getBlockHeader().getWitnessSignature().isEmpty();
349+
}
350+
347351
private StringBuffer toStringBuff = new StringBuffer();
348352

349353
@Override

src/main/java/org/tron/core/db/Manager.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1252,7 +1252,7 @@ public TransactionInfo processTransaction(final TransactionCapsule trxCap, Block
12521252

12531253
if (Objects.nonNull(blockCap)) {
12541254
trace.setResult();
1255-
if (!blockCap.getInstance().getBlockHeader().getWitnessSignature().isEmpty()) {
1255+
if (blockCap.hasWitnessSignature()) {
12561256
if (trace.checkNeedRetry()) {
12571257
String txId = Hex.toHexString(trxCap.getTransactionId().getBytes());
12581258
logger.info("Retry for tx id: {}", txId);
@@ -1682,7 +1682,7 @@ private void processMaintenance(BlockCapsule block) {
16821682

16831683
/**
16841684
* @param block the block update signed witness. set witness who signed block the 1. the latest
1685-
* block num 2. pay the trx to witness. 3. the latest slot num.
1685+
* block num 2. pay the trx to witness. 3. the latest slot num.
16861686
*/
16871687
public void updateSignedWitness(BlockCapsule block) {
16881688
// TODO: add verification

src/test/java/org/tron/core/capsule/BlockCapsuleTest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,15 @@ public void testGetInsHash() {
119119
Sha256Hash.wrap(blockCapsule0.getParentHashStr()));
120120
}
121121

122+
@Test
123+
public void testHasWitnessSignature() {
124+
125+
Assert.assertFalse(blockCapsule0.hasWitnessSignature());
126+
blockCapsule0
127+
.sign(ByteArray.fromHexString(Args.getInstance().getLocalWitnesses().getPrivateKey()));
128+
Assert.assertTrue(blockCapsule0.hasWitnessSignature());
129+
}
130+
122131
@Test
123132
public void testGetTimeStamp() {
124133
Assert.assertEquals(1234L, blockCapsule0.getTimeStamp());

0 commit comments

Comments
 (0)