Skip to content

Commit 37f5294

Browse files
committed
fixes and refactoring
1 parent 8f7c1bf commit 37f5294

File tree

9 files changed

+16
-25
lines changed

9 files changed

+16
-25
lines changed

integrationtests/accountsESDTRollback_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ func TestAccountsESDTDeleteOnRollback(t *testing.T) {
9191
require.JSONEq(t, readExpectedResult("./testdata/accountsESDTRollback/account-after-create.json"), string(genericResponse.Docs[0].Source))
9292

9393
// DO ROLLBACK
94-
err = esProc.RemoveAccountsESDT(5040, 2)
94+
err = esProc.RemoveAccountsESDT(2, 5040000)
9595
require.Nil(t, err)
9696

9797
err = esClient.DoMultiGet(context.Background(), ids, indexerdata.AccountsESDTIndex, true, genericResponse)

integrationtests/delegators_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ func TestDelegateUnDelegateAndWithdraw(t *testing.T) {
132132

133133
// revert unDelegate 2
134134
header.TimeStamp = 5060
135-
err = esProc.RemoveTransactions(header, body)
135+
err = esProc.RemoveTransactions(header, body, 5060000)
136136
require.Nil(t, err)
137137

138138
time.Sleep(time.Second)

integrationtests/logsCrossShard_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ func TestIndexLogSourceShardAndAfterDestinationAndAgainSource(t *testing.T) {
208208
},
209209
}
210210

211-
err = esProc.RemoveTransactions(header, body)
211+
err = esProc.RemoveTransactions(header, body, header.TimeStamp*1000)
212212
require.Nil(t, err)
213213

214214
err = esClient.DoMultiGet(context.Background(), ids, indexerdata.LogsIndex, true, genericResponse)

mock/elasticProcessorStub.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ type ElasticProcessorStub struct {
1818
SaveRoundsInfoCalled func(infos *outport.RoundsInfo) error
1919
SaveShardValidatorsPubKeysCalled func(validators *outport.ValidatorsPubKeys) error
2020
SaveAccountsCalled func(accountsData *outport.Accounts) error
21-
RemoveAccountsESDTCalled func(headerTimestamp uint64) error
21+
RemoveAccountsESDTCalled func(shardID uint32, timestampMS uint64) error
2222
}
2323

2424
// RemoveAccountsESDT -
25-
func (eim *ElasticProcessorStub) RemoveAccountsESDT(headerTimestamp uint64, _ uint32, _ uint64) error {
25+
func (eim *ElasticProcessorStub) RemoveAccountsESDT(shardID uint32, timestampMS uint64) error {
2626
if eim.RemoveAccountsESDTCalled != nil {
27-
return eim.RemoveAccountsESDTCalled(headerTimestamp)
27+
return eim.RemoveAccountsESDTCalled(shardID, timestampMS)
2828
}
2929

3030
return nil

process/dataindexer/dataIndexer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ func (di *dataIndexer) RevertIndexedBlock(blockData *outport.BlockData) error {
157157
return err
158158
}
159159

160-
return di.elasticProcessor.RemoveAccountsESDT(header.GetTimeStamp(), header.GetShardID(), blockData.TimestampMs)
160+
return di.elasticProcessor.RemoveAccountsESDT(header.GetShardID(), blockData.TimestampMs)
161161
}
162162

163163
// SaveRoundsInfo will save data about a slice of rounds in elasticsearch

process/dataindexer/dataIndexer_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ func TestDataIndexer_RevertIndexedBlock(t *testing.T) {
167167
countMap[2]++
168168
return nil
169169
},
170-
RemoveAccountsESDTCalled: func(headerTimestamp uint64) error {
170+
RemoveAccountsESDTCalled: func(_ uint32, _ uint64) error {
171171
countMap[3]++
172172
return nil
173173
},

process/dataindexer/interface.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ type ElasticProcessor interface {
1616
RemoveHeader(header coreData.HeaderHandler) error
1717
RemoveMiniblocks(header coreData.HeaderHandler, body *block.Body) error
1818
RemoveTransactions(header coreData.HeaderHandler, body *block.Body, uint65 uint64) error
19-
RemoveAccountsESDT(headerTimestamp uint64, shardID uint32, timestampMS uint64) error
19+
RemoveAccountsESDT(shardID uint32, timestampMS uint64) error
2020
SaveMiniblocks(header coreData.HeaderHandler, miniBlocks []*block.MiniBlock, timestampMS uint64) error
2121
SaveTransactions(outportBlockWithHeader *outport.OutportBlockWithHeader) error
2222
SaveValidatorsRating(ratingData *outport.ValidatorsRating) error

process/elasticproc/elasticProcessor.go

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -341,11 +341,7 @@ func (ei *elasticProcessor) RemoveTransactions(header coreData.HeaderHandler, bo
341341
return err
342342
}
343343

344-
timestamp := header.GetTimeStamp()
345-
if timestampMs > 0 {
346-
timestamp = timestampMs
347-
}
348-
err = ei.removeFromIndexByTimestampAndShardID(timestamp, header.GetShardID(), elasticIndexer.EventsIndex)
344+
err = ei.removeFromIndexByTimestampAndShardID(header.GetShardID(), elasticIndexer.EventsIndex, timestampMs)
349345
if err != nil {
350346
return err
351347
}
@@ -382,23 +378,18 @@ func (ei *elasticProcessor) removeIfHashesNotEmpty(index string, hashes []string
382378
}
383379

384380
// RemoveAccountsESDT will remove data from accountsesdt index and accountsesdthistory
385-
func (ei *elasticProcessor) RemoveAccountsESDT(headerTimestamp uint64, shardID uint32, timestampMs uint64) error {
386-
timestamp := headerTimestamp
387-
if timestampMs > 0 {
388-
timestamp = timestampMs
389-
}
390-
391-
err := ei.removeFromIndexByTimestampAndShardID(timestamp, shardID, elasticIndexer.AccountsESDTIndex)
381+
func (ei *elasticProcessor) RemoveAccountsESDT(shardID uint32, timestampMs uint64) error {
382+
err := ei.removeFromIndexByTimestampAndShardID(shardID, elasticIndexer.AccountsESDTIndex, timestampMs)
392383
if err != nil {
393384
return err
394385
}
395386

396-
return ei.removeFromIndexByTimestampAndShardID(timestamp, shardID, elasticIndexer.AccountsESDTHistoryIndex)
387+
return ei.removeFromIndexByTimestampAndShardID(shardID, elasticIndexer.AccountsESDTHistoryIndex, timestampMs)
397388
}
398389

399-
func (ei *elasticProcessor) removeFromIndexByTimestampAndShardID(headerTimestamp uint64, shardID uint32, index string) error {
390+
func (ei *elasticProcessor) removeFromIndexByTimestampAndShardID(shardID uint32, index string, timestampMs uint64) error {
400391
ctxWithValue := context.WithValue(context.Background(), request.ContextKey, request.ExtendTopicWithShardID(request.RemoveTopic, shardID))
401-
query := fmt.Sprintf(`{"query": {"bool": {"must": [{"match": {"shardID": {"query": %d,"operator": "AND"}}},{"match": {"timestamp": {"query": "%d","operator": "AND"}}}]}}}`, shardID, headerTimestamp)
392+
query := fmt.Sprintf(`{"query": {"bool": {"must": [{"match": {"shardID": {"query": %d,"operator": "AND"}}},{"match": {"timestampMs": {"query": "%d","operator": "AND"}}}]}}}`, shardID, timestampMs)
402393

403394
return ei.elasticClient.DoQueryRemove(
404395
ctxWithValue,

process/elasticproc/elasticProcessor_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ func TestElasticProcessor_RemoveTransactions(t *testing.T) {
481481
called = true
482482
} else {
483483
require.Equal(t,
484-
`{"query": {"bool": {"must": [{"match": {"shardID": {"query": 4294967295,"operator": "AND"}}},{"match": {"timestamp": {"query": "0","operator": "AND"}}}]}}}`,
484+
`{"query": {"bool": {"must": [{"match": {"shardID": {"query": 4294967295,"operator": "AND"}}},{"match": {"timestampMs": {"query": "0","operator": "AND"}}}]}}}`,
485485
body.String(),
486486
)
487487
}

0 commit comments

Comments
 (0)