Skip to content

Commit d8616e8

Browse files
committed
fix(jsonrpc): drop data from 4444 and remove ResultCodeUtil
- 4444 no longer carries the earliest available block in data, as geth - remove ResultCodeUtil; constant calls record only REVERT
1 parent c164330 commit d8616e8

9 files changed

Lines changed: 24 additions & 174 deletions

File tree

‎chainbase/src/main/java/org/tron/core/ChainBaseManager.java‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,6 @@ public class ChainBaseManager {
248248

249249
// lowest block with receipts; above lowestBlockNum on a LiteNode
250250
@Getter
251-
@Setter
252251
private long lowestReceiptBlockNum = -1;
253252

254253
@Getter

‎chainbase/src/main/java/org/tron/core/store/TransactionRetStore.java‎

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import com.google.common.primitives.Longs;
44
import com.google.protobuf.ByteString;
5-
import java.util.Map;
65
import java.util.Objects;
76
import java.util.OptionalLong;
87
import lombok.extern.slf4j.Slf4j;
@@ -48,13 +47,8 @@ public void put(byte[] key, TransactionRetCapsule item) {
4847
* layers, {@code getNext} does not merge deletions correctly.
4948
*/
5049
public OptionalLong getLowestBlockNum() {
51-
Map<byte[], byte[]> entries = revokingDB.getNext(ByteArray.fromLong(0), 1);
52-
for (byte[] key : entries.keySet()) {
53-
if (key.length == Long.BYTES) {
54-
return OptionalLong.of(Longs.fromByteArray(key));
55-
}
56-
}
57-
return OptionalLong.empty();
50+
return revokingDB.getNext(ByteArray.fromLong(0), 1).keySet().stream()
51+
.mapToLong(Longs::fromByteArray).findFirst();
5852
}
5953

6054
public TransactionInfoCapsule getTransactionInfo(byte[] key) throws BadItemException {

‎common/src/main/java/org/tron/core/exception/jsonrpc/JsonRpcPrunedHistoryException.java‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package org.tron.core.exception.jsonrpc;
22

33
/**
4-
* Thrown when a request targets historical state that a LiteNode has pruned.
5-
* Maps to JSON-RPC error code 4444 "Pruned history unavailable", as standardized
6-
* by the Ethereum Execution API (EIP-4444).
4+
* Thrown when a request targets data the node does not have: history pruned on a LiteNode,
5+
* or receipts and logs on a node that does not persist them. Maps to JSON-RPC error code 4444
6+
* "Pruned history unavailable", as standardized by the Ethereum Execution API (EIP-4444).
77
*/
88
public class JsonRpcPrunedHistoryException extends JsonRpcException {
99

‎framework/src/main/java/org/tron/core/Wallet.java‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,6 @@
201201
import org.tron.core.store.StoreFactory;
202202
import org.tron.core.store.VotesStore;
203203
import org.tron.core.store.WitnessStore;
204-
import org.tron.core.utils.ResultCodeUtil;
205204
import org.tron.core.utils.TransactionUtil;
206205
import org.tron.core.vm.config.VMConfig;
207206
import org.tron.core.vm.program.Program;
@@ -3200,8 +3199,6 @@ public Transaction callConstantContract(TransactionCapsule trxCap,
32003199
ret.setStatus(0, code.SUCESS);
32013200
if (StringUtils.isNoneEmpty(result.getRuntimeError())) {
32023201
ret.setStatus(0, code.FAILED);
3203-
// same failure classification as executed transactions
3204-
ret.setResultCode(ResultCodeUtil.resolve(result.getException()));
32053202
retBuilder
32063203
.setMessage(ByteString.copyFromUtf8(result.getRuntimeError()))
32073204
.build();

‎framework/src/main/java/org/tron/core/services/jsonrpc/JsonRpcApiUtil.java‎

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,7 @@ public static long parseBlockNumber(String blockNumOrTag, Wallet wallet)
704704

705705
/**
706706
* The lowest block for which everything the node persists is available; what "earliest"
707-
* resolves to and what a 4444 error carries in {@code data}. On a LiteNode this is the
707+
* resolves to. On a LiteNode this is the
708708
* receipt floor when receipts are persisted, otherwise the body floor (receipt endpoints
709709
* answer 4444 on such a node regardless of this value). On a FullNode it is genesis.
710710
*/
@@ -723,7 +723,7 @@ public static long earliestAvailableBlock(Wallet wallet) {
723723
public static void checkPrunedHistory(long blockNum, Wallet wallet)
724724
throws JsonRpcPrunedHistoryException {
725725
if (wallet.isLiteNode() && blockNum < wallet.getLowestBlockNum()) {
726-
throw prunedHistory(earliestAvailableBlock(wallet));
726+
throw new JsonRpcPrunedHistoryException(PRUNED_HISTORY_ERROR);
727727
}
728728
}
729729

@@ -736,21 +736,9 @@ public static void checkPrunedHistory(long blockNum, Wallet wallet)
736736
public static void checkPrunedReceiptHistory(long blockNum, Wallet wallet)
737737
throws JsonRpcPrunedHistoryException {
738738
long receiptFloor = wallet.getLowestReceiptBlockNum();
739-
if (receiptFloor == Long.MAX_VALUE) {
739+
if (receiptFloor == Long.MAX_VALUE || wallet.isLiteNode() && blockNum < receiptFloor) {
740740
throw new JsonRpcPrunedHistoryException(PRUNED_HISTORY_ERROR);
741741
}
742-
if (wallet.isLiteNode() && blockNum < receiptFloor) {
743-
throw prunedHistory(receiptFloor);
744-
}
745-
}
746-
747-
/**
748-
* The Execution API fixes the message verbatim; the earliest available block travels in
749-
* {@code data} so a client can pick a fallback node from it.
750-
*/
751-
private static JsonRpcPrunedHistoryException prunedHistory(long earliestAvailable) {
752-
return new JsonRpcPrunedHistoryException(PRUNED_HISTORY_ERROR,
753-
"0x" + Long.toHexString(earliestAvailable));
754742
}
755743

756744
/**

‎framework/src/main/java/org/tron/core/services/jsonrpc/TronJsonRpcImpl.java‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -934,6 +934,7 @@ private TransactionContext findTransactionContext(TransactionInfoList infoList,
934934
* @return List of TransactionReceipt objects for all transactions in the block,
935935
* null if block not found
936936
* @throws JsonRpcInvalidParamsException if the parameter format is invalid
937+
* @throws JsonRpcPrunedHistoryException if the node does not have the block's receipts
937938
* @throws JsonRpcInternalException if there's an internal error
938939
*/
939940
@Override
@@ -950,14 +951,13 @@ public List<TransactionReceipt> getBlockReceipts(String blockNumOrHashOrTag)
950951
block = getBlockByNumOrTag(blockNumOrHashOrTag);
951952
}
952953

953-
// block receipts not available: block is genesis, not produced yet, or pruned in light node
954+
// block receipts not available: block is genesis, not produced yet, or unknown hash
954955
if (block == null || block.getBlockHeader().getRawData().getNumber() == 0) {
955956
return null;
956957
}
957958

958959
BlockCapsule blockCapsule = new BlockCapsule(block);
959960
long blockNum = blockCapsule.getNum();
960-
int transactionSizeInBlock = blockCapsule.getTransactions().size();
961961
// below the receipt floor the body exists but the receipts do not — 4444, not -32000
962962
JsonRpcApiUtil.checkPrunedReceiptHistory(blockNum, wallet);
963963
TransactionInfoList transactionInfoList = wallet.getTransactionInfoByBlockNum(blockNum);
@@ -966,6 +966,7 @@ public List<TransactionReceipt> getBlockReceipts(String blockNumOrHashOrTag)
966966
long energyFee = wallet.getEnergyFee(blockCapsule.getTimeStamp());
967967

968968
// Validate transaction list size consistency
969+
int transactionSizeInBlock = blockCapsule.getTransactions().size();
969970
if (transactionSizeInBlock != transactionInfoList.getTransactionInfoCount()) {
970971
throw new JsonRpcInternalException(
971972
String.format("TransactionList size mismatch: "

‎framework/src/main/java/org/tron/core/utils/ResultCodeUtil.java‎

Lines changed: 0 additions & 48 deletions
This file was deleted.

‎framework/src/test/java/org/tron/core/jsonrpc/JsonRpcPrunedHistoryTest.java‎

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ public class JsonRpcPrunedHistoryTest {
2929
private static final long RECEIPT_FLOOR_BLOCK_NUM = 150L;
3030
private static final long HEAD_BLOCK_NUM = 200L;
3131
private static final String PRUNED_MESSAGE = "Pruned history unavailable";
32-
private static final String BODY_FLOOR_HEX = "0x64";
3332
private static final String BELOW_CUTOFF_HEX = "0x10";
3433
private static final String AT_CUTOFF_HEX = "0x64";
3534
private static final long IN_RECEIPT_GAP_NUM = 112L;
@@ -101,18 +100,7 @@ public void testGetBlockByNumberBelowCutoffReturns4444() {
101100
JsonRpcPrunedHistoryException e = assertThrows(JsonRpcPrunedHistoryException.class,
102101
() -> liteRpc.ethGetBlockByNumber(BELOW_CUTOFF_HEX, false));
103102
Assert.assertEquals(PRUNED_MESSAGE, e.getMessage());
104-
// data carries the same height "earliest" resolves to, not the endpoint's own floor
105-
Assert.assertEquals(RECEIPT_FLOOR_HEX, e.getData());
106-
}
107-
108-
@Test
109-
public void testGetBlockByNumberBelowCutoffWithHistoryOffReportsBodyFloor() {
110-
rpc = new TronJsonRpcImpl(mock(NodeInfoService.class), newHistoryOffMockWallet());
111-
112-
JsonRpcPrunedHistoryException e = assertThrows(JsonRpcPrunedHistoryException.class,
113-
() -> rpc.ethGetBlockByNumber(BELOW_CUTOFF_HEX, false));
114-
Assert.assertEquals(PRUNED_MESSAGE, e.getMessage());
115-
Assert.assertEquals(BODY_FLOOR_HEX, e.getData());
103+
Assert.assertNull(e.getData());
116104
}
117105

118106
@Test
@@ -167,7 +155,7 @@ public void testGetBlockTransactionCountBelowCutoffReturns4444() {
167155
JsonRpcPrunedHistoryException e = assertThrows(JsonRpcPrunedHistoryException.class,
168156
() -> liteRpc.ethGetBlockTransactionCountByNumber(BELOW_CUTOFF_HEX));
169157
Assert.assertEquals(PRUNED_MESSAGE, e.getMessage());
170-
Assert.assertEquals(RECEIPT_FLOOR_HEX, e.getData());
158+
Assert.assertNull(e.getData());
171159
}
172160

173161
@Test
@@ -177,7 +165,7 @@ public void testGetTransactionByBlockNumberAndIndexBelowCutoffReturns4444() {
177165
JsonRpcPrunedHistoryException e = assertThrows(JsonRpcPrunedHistoryException.class,
178166
() -> liteRpc.getTransactionByBlockNumberAndIndex(BELOW_CUTOFF_HEX, "0x0"));
179167
Assert.assertEquals(PRUNED_MESSAGE, e.getMessage());
180-
Assert.assertEquals(RECEIPT_FLOOR_HEX, e.getData());
168+
Assert.assertNull(e.getData());
181169
}
182170

183171
@Test
@@ -187,18 +175,15 @@ public void testGetBlockReceiptsBelowCutoffReturns4444() {
187175
JsonRpcPrunedHistoryException e = assertThrows(JsonRpcPrunedHistoryException.class,
188176
() -> liteRpc.getBlockReceipts(BELOW_CUTOFF_HEX));
189177
Assert.assertEquals(PRUNED_MESSAGE, e.getMessage());
190-
Assert.assertEquals(RECEIPT_FLOOR_HEX, e.getData());
178+
Assert.assertNull(e.getData());
191179
}
192180

193181
@Test
194-
public void testGetBlockReceiptsBelowCutoffWithHistoryOffReportsBodyFloor() {
195-
// with receipts never persisted, "earliest" falls back to the body floor and so does data
182+
public void testGetBlockReceiptsFutureBlockWithHistoryOffReturnsNull() throws Exception {
183+
// a block that does not exist yet is not pruned history
196184
rpc = new TronJsonRpcImpl(mock(NodeInfoService.class), newHistoryOffMockWallet());
197185

198-
JsonRpcPrunedHistoryException e = assertThrows(JsonRpcPrunedHistoryException.class,
199-
() -> rpc.getBlockReceipts(BELOW_CUTOFF_HEX));
200-
Assert.assertEquals(PRUNED_MESSAGE, e.getMessage());
201-
Assert.assertEquals(BODY_FLOOR_HEX, e.getData());
186+
Assert.assertNull(rpc.getBlockReceipts("0x7fffffff"));
202187
}
203188

204189
@Test
@@ -209,7 +194,7 @@ public void testGetLogsFromBlockBelowCutoffReturns4444() {
209194
JsonRpcPrunedHistoryException e = assertThrows(JsonRpcPrunedHistoryException.class,
210195
() -> liteRpc.getLogs(fr));
211196
Assert.assertEquals(PRUNED_MESSAGE, e.getMessage());
212-
Assert.assertEquals(RECEIPT_FLOOR_HEX, e.getData());
197+
Assert.assertNull(e.getData());
213198
}
214199

215200
@Test
@@ -220,7 +205,7 @@ public void testNewFilterFromBlockBelowCutoffReturns4444() {
220205
JsonRpcPrunedHistoryException e = assertThrows(JsonRpcPrunedHistoryException.class,
221206
() -> liteRpc.newFilter(fr));
222207
Assert.assertEquals(PRUNED_MESSAGE, e.getMessage());
223-
Assert.assertEquals(RECEIPT_FLOOR_HEX, e.getData());
208+
Assert.assertNull(e.getData());
224209
}
225210

226211
@Test
@@ -273,7 +258,7 @@ public void testGetLogsInReceiptGapReturns4444() {
273258
JsonRpcPrunedHistoryException e = assertThrows(JsonRpcPrunedHistoryException.class,
274259
() -> liteRpc.getLogs(fr));
275260
Assert.assertEquals(PRUNED_MESSAGE, e.getMessage());
276-
Assert.assertEquals(RECEIPT_FLOOR_HEX, e.getData());
261+
Assert.assertNull(e.getData());
277262
}
278263

279264
@Test
@@ -286,12 +271,12 @@ public void testGetBlockReceiptsInReceiptGapReturns4444() {
286271
JsonRpcPrunedHistoryException e = assertThrows(JsonRpcPrunedHistoryException.class,
287272
() -> rpc.getBlockReceipts(IN_RECEIPT_GAP_HEX));
288273
Assert.assertEquals(PRUNED_MESSAGE, e.getMessage());
289-
Assert.assertEquals(RECEIPT_FLOOR_HEX, e.getData());
274+
Assert.assertNull(e.getData());
290275
}
291276

292277
@Test
293278
public void testGetBlockReceiptsEmptyBlockInReceiptGapReturns4444() {
294-
// the floor is checked before the body is read, so an empty block is not special-cased
279+
// the floor check ignores the transaction count, so an empty block is not special-cased
295280
Wallet wallet = newMockWallet(true);
296281
when(wallet.getBlockByNum(IN_RECEIPT_GAP_NUM))
297282
.thenReturn(newBlock(IN_RECEIPT_GAP_NUM, 0));
@@ -300,7 +285,7 @@ public void testGetBlockReceiptsEmptyBlockInReceiptGapReturns4444() {
300285
JsonRpcPrunedHistoryException e = assertThrows(JsonRpcPrunedHistoryException.class,
301286
() -> rpc.getBlockReceipts(IN_RECEIPT_GAP_HEX));
302287
Assert.assertEquals(PRUNED_MESSAGE, e.getMessage());
303-
Assert.assertEquals(RECEIPT_FLOOR_HEX, e.getData());
288+
Assert.assertNull(e.getData());
304289
}
305290

306291
@Test

‎framework/src/test/java/org/tron/core/utils/ResultCodeUtilTest.java‎

Lines changed: 0 additions & 66 deletions
This file was deleted.

0 commit comments

Comments
 (0)