Skip to content

Commit 704b086

Browse files
authored
HIP-1056 Ignore ethereum transaction callDataId when callData is inlined (#12265)
- Use non-empty inlined callData over data from valid callDataId Signed-off-by: Xin Li <xin@hashgraph.com>
1 parent 61b7be8 commit 704b086

2 files changed

Lines changed: 35 additions & 12 deletions

File tree

importer/src/main/java/org/hiero/mirror/importer/parser/record/transactionhandler/EthereumTransactionHandler.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ public void updateContractResult(ContractResult contractResult, RecordItem recor
7878

7979
byte[] callData = ethereumTransaction.getCallData();
8080
var callDataId = ethereumTransaction.getCallDataId();
81-
if (callDataId != null) {
81+
if (ArrayUtils.isEmpty(callData) && !EntityId.isEmpty(callDataId)) {
82+
// call data file (callDataId) is ignored by consensus node if there's call data in ethereum data
8283
callData = contractBytecodeService.get(callDataId);
8384
if (callData == null) {
8485
Utility.handleRecoverableError(

importer/src/test/java/org/hiero/mirror/importer/parser/record/transactionhandler/EthereumTransactionHandlerTest.java

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -120,43 +120,65 @@ void getEntityId(boolean create) {
120120
@CsvSource(
121121
textBlock =
122122
"""
123-
'abab', true, , 'abab'
124-
'', true, , ''
125-
, true, , ''
126-
, false, 'abab', 'abab'
127-
, false, '', ''
128-
, false, , ''
123+
'abab', , 'abab'
124+
, 'abab', 'abab'
125+
'abab', 'efef', 'abab'
126+
, , ''
129127
""")
130128
void updateContractResult(
131129
@ConvertWith(HexToByteArrayConverter.class) byte[] callData,
132-
boolean callDataInlined,
133130
@ConvertWith(HexToByteArrayConverter.class) byte[] callDataInFile,
134131
@ConvertWith(HexToByteArrayConverter.class) byte[] expectedFunctionParameters) {
135132
// given
136133
var contractResult = new ContractResult();
134+
boolean callDataInlined = callData != null;
135+
var callDataId = callDataInFile != null ? domainBuilder.entityId() : null;
137136
var ethereumTransaction = domainBuilder
138137
.ethereumTransaction(callDataInlined)
139-
.customize(e -> e.callData(callData))
138+
.customize(e -> e.callData(callData).callDataId(callDataId))
140139
.get();
141140
var recordItem = recordItemBuilder
142141
.ethereumTransaction()
143142
.recordItem(r -> r.blockstream(true).ethereumTransaction(ethereumTransaction))
144143
.build();
145-
if (!callDataInlined) {
146-
doReturn(callDataInFile).when(contractBytecodeService).get(ethereumTransaction.getCallDataId());
144+
boolean expectCallDataFromFile = !callDataInlined && callDataId != null;
145+
if (expectCallDataFromFile) {
146+
doReturn(callDataInFile).when(contractBytecodeService).get(callDataId);
147147
}
148148

149149
// when
150150
transactionHandler.updateContractResult(contractResult, recordItem);
151151

152152
// then
153-
verify(contractBytecodeService, times(callDataInlined ? 0 : 1)).get(any(EntityId.class));
153+
verify(contractBytecodeService, times(expectCallDataFromFile ? 1 : 0)).get(any(EntityId.class));
154154
assertThat(contractResult)
155155
.returns(new BigInteger(ethereumTransaction.getValue()).longValue(), ContractResult::getAmount)
156156
.returns(expectedFunctionParameters, ContractResult::getFunctionParameters)
157157
.returns(ethereumTransaction.getGasLimit(), ContractResult::getGasLimit);
158158
}
159159

160+
@Test
161+
void updateContractResultWithNullFromCallDataId() {
162+
// given
163+
var contractResult = new ContractResult();
164+
var ethereumTransaction = domainBuilder.ethereumTransaction(false).get();
165+
var recordItem = recordItemBuilder
166+
.ethereumTransaction()
167+
.recordItem(r -> r.blockstream(true).ethereumTransaction(ethereumTransaction))
168+
.build();
169+
doReturn(null).when(contractBytecodeService).get(ethereumTransaction.getCallDataId());
170+
171+
// when
172+
transactionHandler.updateContractResult(contractResult, recordItem);
173+
174+
// then
175+
verify(contractBytecodeService).get(ethereumTransaction.getCallDataId());
176+
assertThat(contractResult)
177+
.returns(new BigInteger(ethereumTransaction.getValue()).longValue(), ContractResult::getAmount)
178+
.returns(EMPTY_BYTE_ARRAY, ContractResult::getFunctionParameters)
179+
.returns(ethereumTransaction.getGasLimit(), ContractResult::getGasLimit);
180+
}
181+
160182
@Test
161183
void updateContractResultNullEthereumTransaction() {
162184
// given

0 commit comments

Comments
 (0)