Skip to content

Commit bdd1a7b

Browse files
authored
Merge pull request #352 from multiversx/rc/barnard-patch-3
Rc/barnard patch 3
2 parents d314dc4 + d541c70 commit bdd1a7b

File tree

14 files changed

+108
-39
lines changed

14 files changed

+108
-39
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# relayed-transactions-v1v2-disable-epoch represents the epoch when relayed transactions v1 and v2 are disabled
2+
relayed-transactions-v1v2-disable-epoch = 3

cmd/elasticindexer/flags.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ var (
2929
"all available routes for Rest API and options to enable or disable them.",
3030
Value: "config/api.toml",
3131
}
32+
configurationEnableEpochsFile = cli.StringFlag{
33+
Name: "config-enable-epochs",
34+
Usage: "The configuration file for the activation epochs",
35+
Value: "./config/enableEpochs.toml",
36+
}
3237

3338
logLevel = cli.StringFlag{
3439
Name: "log-level",

cmd/elasticindexer/main.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ func main() {
5858
app.Usage = "This tool will index data in an Elasticsearch database"
5959
app.Flags = []cli.Flag{
6060
configurationFile,
61+
configurationEnableEpochsFile,
6162
configurationPreferencesFile,
6263
configurationApiFile,
6364
logLevel,
@@ -97,8 +98,13 @@ func startIndexer(ctx *cli.Context) error {
9798
return fmt.Errorf("%w while initializing the logger", err)
9899
}
99100

101+
epochsCfg, err := loadEpochsConfig(ctx.GlobalString(configurationEnableEpochsFile.Name))
102+
if err != nil {
103+
return fmt.Errorf("%w while loading the enable epochs config file", err)
104+
}
105+
100106
statusMetrics := metrics.NewStatusMetrics()
101-
wsHost, err := factory.CreateWsIndexer(cfg, clusterCfg, statusMetrics, ctx.App.Version)
107+
wsHost, err := factory.CreateWsIndexer(cfg, clusterCfg, epochsCfg, statusMetrics, ctx.App.Version)
102108
if err != nil {
103109
return fmt.Errorf("%w while creating the indexer", err)
104110
}
@@ -173,6 +179,13 @@ func loadMainConfig(filepath string) (config.Config, error) {
173179
return cfg, err
174180
}
175181

182+
func loadEpochsConfig(filepath string) (config.EnableEpochsConfig, error) {
183+
cfg := config.EnableEpochsConfig{}
184+
err := core.LoadTomlFile(&cfg, filepath)
185+
186+
return cfg, err
187+
}
188+
176189
func loadClusterConfig(filepath string) (config.ClusterConfig, error) {
177190
cfg := config.ClusterConfig{}
178191
err := core.LoadTomlFile(&cfg, filepath)

config/config.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,8 @@ type RouteConfig struct {
7070
Name string `toml:"name"`
7171
Open bool `toml:"open"`
7272
}
73+
74+
// EnableEpochsConfig holds the configuration for activation epochs
75+
type EnableEpochsConfig struct {
76+
RelayedTransactionsV1V2DisableEpoch uint32 `toml:"relayed-transactions-v1v2-disable-epoch"`
77+
}

factory/wsIndexerFactory.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,19 @@ import (
1717
var log = logger.GetOrCreate("elasticindexer")
1818

1919
// CreateWsIndexer will create a new instance of wsindexer.WSClient
20-
func CreateWsIndexer(cfg config.Config, clusterCfg config.ClusterConfig, statusMetrics core.StatusMetricsHandler, version string) (wsindexer.WSClient, error) {
20+
func CreateWsIndexer(
21+
cfg config.Config,
22+
clusterCfg config.ClusterConfig,
23+
epochsCfg config.EnableEpochsConfig,
24+
statusMetrics core.StatusMetricsHandler,
25+
version string,
26+
) (wsindexer.WSClient, error) {
2127
wsMarshaller, err := factoryMarshaller.NewMarshalizer(clusterCfg.Config.WebSocket.DataMarshallerType)
2228
if err != nil {
2329
return nil, err
2430
}
2531

26-
dataIndexer, err := createDataIndexer(cfg, clusterCfg, wsMarshaller, statusMetrics, version)
32+
dataIndexer, err := createDataIndexer(cfg, clusterCfg, epochsCfg, wsMarshaller, statusMetrics, version)
2733
if err != nil {
2834
return nil, err
2935
}
@@ -54,6 +60,7 @@ func CreateWsIndexer(cfg config.Config, clusterCfg config.ClusterConfig, statusM
5460
func createDataIndexer(
5561
cfg config.Config,
5662
clusterCfg config.ClusterConfig,
63+
enableEpochsCfg config.EnableEpochsConfig,
5764
wsMarshaller marshal.Marshalizer,
5865
statusMetrics core.StatusMetricsHandler,
5966
version string,
@@ -90,6 +97,7 @@ func createDataIndexer(
9097
HeaderMarshaller: wsMarshaller,
9198
StatusMetrics: statusMetrics,
9299
Version: version,
100+
EnableEpochsConfig: enableEpochsCfg,
93101
})
94102
}
95103

integrationtests/utils.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/multiversx/mx-chain-core-go/core/pubkeyConverter"
1414
"github.com/multiversx/mx-chain-es-indexer-go/client"
1515
"github.com/multiversx/mx-chain-es-indexer-go/client/logging"
16+
"github.com/multiversx/mx-chain-es-indexer-go/config"
1617
"github.com/multiversx/mx-chain-es-indexer-go/mock"
1718
"github.com/multiversx/mx-chain-es-indexer-go/process/dataindexer"
1819
"github.com/multiversx/mx-chain-es-indexer-go/process/elasticproc"
@@ -61,6 +62,9 @@ func CreateElasticProcessor(
6162
dataindexer.ReceiptsIndex, dataindexer.BlockIndex, dataindexer.AccountsIndex, dataindexer.TokensIndex, dataindexer.TagsIndex, dataindexer.EventsIndex,
6263
dataindexer.OperationsIndex, dataindexer.DelegatorsIndex, dataindexer.ESDTsIndex, dataindexer.SCDeploysIndex, dataindexer.MiniblocksIndex, dataindexer.ValuesIndex},
6364
Denomination: 18,
65+
EnableEpochsConfig: config.EnableEpochsConfig{
66+
RelayedTransactionsV1V2DisableEpoch: 1,
67+
},
6468
}
6569

6670
return factory.CreateElasticProcessor(args)

process/elasticproc/block/blockProcessor.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ import (
44
"encoding/hex"
55
"errors"
66
"fmt"
7+
"strconv"
8+
79
"github.com/multiversx/mx-chain-core-go/core"
810
"github.com/multiversx/mx-chain-core-go/core/check"
911
coreData "github.com/multiversx/mx-chain-core-go/data"
1012
"github.com/multiversx/mx-chain-core-go/data/api"
11-
"github.com/multiversx/mx-chain-core-go/data/block"
1213
nodeBlock "github.com/multiversx/mx-chain-core-go/data/block"
1314
"github.com/multiversx/mx-chain-core-go/data/outport"
1415
"github.com/multiversx/mx-chain-core-go/hashing"
@@ -17,7 +18,6 @@ import (
1718
indexer "github.com/multiversx/mx-chain-es-indexer-go/process/dataindexer"
1819
"github.com/multiversx/mx-chain-es-indexer-go/process/elasticproc/converters"
1920
logger "github.com/multiversx/mx-chain-logger-go"
20-
"strconv"
2121
)
2222

2323
const (
@@ -188,7 +188,7 @@ func getTxsCount(header coreData.HeaderHandler) (numTxs, notarizedTxs uint32) {
188188
notarizedTxs = metaHeader.TxCount
189189
numTxs = 0
190190
for _, mb := range metaHeader.MiniBlockHeaders {
191-
if mb.Type == block.PeerBlock {
191+
if mb.Type == nodeBlock.PeerBlock {
192192
continue
193193
}
194194

@@ -269,7 +269,7 @@ func (bp *blockProcessor) addEpochStartShardDataForMeta(epochStartShardData node
269269
block.EpochStartShardsData = append(block.EpochStartShardsData, shardData)
270270
}
271271

272-
func (bp *blockProcessor) getEncodedMBSHashes(body *block.Body, intraShardMbs []*nodeBlock.MiniBlock) []string {
272+
func (bp *blockProcessor) getEncodedMBSHashes(body *nodeBlock.Body, intraShardMbs []*nodeBlock.MiniBlock) []string {
273273
miniblocksHashes := make([]string, 0)
274274
mbs := append(body.MiniBlocks, intraShardMbs...)
275275
for _, miniblock := range mbs {
@@ -287,7 +287,7 @@ func (bp *blockProcessor) getEncodedMBSHashes(body *block.Body, intraShardMbs []
287287
return miniblocksHashes
288288
}
289289

290-
func appendBlockDetailsFromHeaders(block *data.Block, header coreData.HeaderHandler, body *block.Body, pool *outport.TransactionPool) {
290+
func appendBlockDetailsFromHeaders(block *data.Block, header coreData.HeaderHandler, body *nodeBlock.Body, pool *outport.TransactionPool) {
291291
for idx, mbHeader := range header.GetMiniBlockHeaderHandlers() {
292292
mbType := nodeBlock.Type(mbHeader.GetTypeInt32())
293293
if mbType == nodeBlock.PeerBlock {
@@ -309,7 +309,7 @@ func appendBlockDetailsFromHeaders(block *data.Block, header coreData.HeaderHand
309309
}
310310
}
311311

312-
func appendBlockDetailsFromIntraShardMbs(block *data.Block, intraShardMbs []*block.MiniBlock, pool *outport.TransactionPool, offset int) {
312+
func appendBlockDetailsFromIntraShardMbs(block *data.Block, intraShardMbs []*nodeBlock.MiniBlock, pool *outport.TransactionPool, offset int) {
313313
for idx, intraMB := range intraShardMbs {
314314
if intraMB.Type == nodeBlock.PeerBlock || intraMB.Type == nodeBlock.ReceiptBlock {
315315
continue
@@ -329,7 +329,7 @@ func appendBlockDetailsFromIntraShardMbs(block *data.Block, intraShardMbs []*blo
329329
}
330330
}
331331

332-
func extractExecutionOrderIntraShardMBUnsigned(mb *block.MiniBlock, pool *outport.TransactionPool) []int {
332+
func extractExecutionOrderIntraShardMBUnsigned(mb *nodeBlock.MiniBlock, pool *outport.TransactionPool) []int {
333333
executionOrderTxsIndices := make([]int, len(mb.TxHashes))
334334
for idx, txHash := range mb.TxHashes {
335335
executionOrder, found := getExecutionOrderForTx(txHash, int32(mb.Type), pool)
@@ -396,7 +396,7 @@ func getExecutionOrderForTx(txHash []byte, mbType int32, pool *outport.Transacti
396396
return tx.GetExecutionOrder(), true
397397
}
398398

399-
func (bp *blockProcessor) computeBlockSize(headerBytes []byte, body *block.Body) (int, error) {
399+
func (bp *blockProcessor) computeBlockSize(headerBytes []byte, body *nodeBlock.Body) (int, error) {
400400
bodyBytes, err := bp.marshalizer.Marshal(body)
401401
if err != nil {
402402
return 0, err

process/elasticproc/factory/elasticProcessorFactory.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"github.com/multiversx/mx-chain-core-go/core"
55
"github.com/multiversx/mx-chain-core-go/hashing"
66
"github.com/multiversx/mx-chain-core-go/marshal"
7+
"github.com/multiversx/mx-chain-es-indexer-go/config"
78
"github.com/multiversx/mx-chain-es-indexer-go/process/dataindexer"
89
"github.com/multiversx/mx-chain-es-indexer-go/process/elasticproc"
910
"github.com/multiversx/mx-chain-es-indexer-go/process/elasticproc/accounts"
@@ -31,6 +32,7 @@ type ArgElasticProcessorFactory struct {
3132
BulkRequestMaxSize int
3233
UseKibana bool
3334
ImportDB bool
35+
EnableEpochsConfig config.EnableEpochsConfig
3436
}
3537

3638
// CreateElasticProcessor will create a new instance of ElasticProcessor
@@ -79,6 +81,7 @@ func CreateElasticProcessor(arguments ArgElasticProcessorFactory) (dataindexer.E
7981
Hasher: arguments.Hasher,
8082
Marshalizer: arguments.Marshalizer,
8183
BalanceConverter: balanceConverter,
84+
EnableEpochsConfig: arguments.EnableEpochsConfig,
8285
}
8386
txsProc, err := transactions.NewTransactionsProcessor(argsTxsProc)
8487
if err != nil {

process/elasticproc/transactions/smartContractResultsProcessor.go

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package transactions
22

33
import (
44
"encoding/hex"
5+
"strconv"
6+
57
"github.com/multiversx/mx-chain-core-go/core"
68
coreData "github.com/multiversx/mx-chain-core-go/data"
79
"github.com/multiversx/mx-chain-core-go/data/block"
@@ -11,15 +13,15 @@ import (
1113
indexerData "github.com/multiversx/mx-chain-es-indexer-go/data"
1214
"github.com/multiversx/mx-chain-es-indexer-go/process/dataindexer"
1315
"github.com/multiversx/mx-chain-es-indexer-go/process/elasticproc/converters"
14-
"strconv"
1516
)
1617

1718
type smartContractResultsProcessor struct {
18-
pubKeyConverter core.PubkeyConverter
19-
hasher hashing.Hasher
20-
marshalizer marshal.Marshalizer
21-
dataFieldParser DataFieldParser
22-
balanceConverter dataindexer.BalanceConverter
19+
pubKeyConverter core.PubkeyConverter
20+
hasher hashing.Hasher
21+
marshalizer marshal.Marshalizer
22+
dataFieldParser DataFieldParser
23+
balanceConverter dataindexer.BalanceConverter
24+
relayedV1V2DisableEpoch uint32
2325
}
2426

2527
func newSmartContractResultsProcessor(
@@ -28,13 +30,15 @@ func newSmartContractResultsProcessor(
2830
hasher hashing.Hasher,
2931
dataFieldParser DataFieldParser,
3032
balanceConverter dataindexer.BalanceConverter,
33+
relayedV1V2DisableEpoch uint32,
3134
) *smartContractResultsProcessor {
3235
return &smartContractResultsProcessor{
33-
pubKeyConverter: pubKeyConverter,
34-
marshalizer: marshalzier,
35-
hasher: hasher,
36-
dataFieldParser: dataFieldParser,
37-
balanceConverter: balanceConverter,
36+
pubKeyConverter: pubKeyConverter,
37+
marshalizer: marshalzier,
38+
hasher: hasher,
39+
dataFieldParser: dataFieldParser,
40+
balanceConverter: balanceConverter,
41+
relayedV1V2DisableEpoch: relayedV1V2DisableEpoch,
3842
}
3943
}
4044

@@ -155,6 +159,8 @@ func (proc *smartContractResultsProcessor) prepareSmartContractResult(
155159
esdtValues = res.ESDTValues
156160
}
157161

162+
isRelayed := res.IsRelayed && header.GetEpoch() < proc.relayedV1V2DisableEpoch
163+
158164
feeInfo := getFeeInfo(scrInfo)
159165
return &indexerData.ScResult{
160166
Hash: scrHashHex,
@@ -186,7 +192,7 @@ func (proc *smartContractResultsProcessor) prepareSmartContractResult(
186192
Tokens: converters.TruncateSliceElementsIfExceedsMaxLength(res.Tokens),
187193
Receivers: receiversAddr,
188194
ReceiversShardIDs: res.ReceiversShardID,
189-
IsRelayed: res.IsRelayed,
195+
IsRelayed: isRelayed,
190196
OriginalSender: originalSenderAddr,
191197
InitialTxFee: feeInfo.Fee.String(),
192198
InitialTxGasUsed: feeInfo.GasUsed,

process/elasticproc/transactions/smartContractResultsProcessor_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ package transactions
22

33
import (
44
"encoding/hex"
5+
"math/big"
6+
"testing"
7+
58
"github.com/multiversx/mx-chain-core-go/data/block"
69
"github.com/multiversx/mx-chain-core-go/data/outport"
710
"github.com/multiversx/mx-chain-core-go/data/smartContractResult"
@@ -10,8 +13,6 @@ import (
1013
"github.com/multiversx/mx-chain-es-indexer-go/process/elasticproc/converters"
1114
datafield "github.com/multiversx/mx-chain-vm-common-go/parsers/dataField"
1215
"github.com/stretchr/testify/require"
13-
"math/big"
14-
"testing"
1516
)
1617

1718
func createDataFieldParserMock() DataFieldParser {
@@ -30,7 +31,7 @@ func TestPrepareSmartContractResult(t *testing.T) {
3031
parser := createDataFieldParserMock()
3132
pubKeyConverter := &mock.PubkeyConverterMock{}
3233
ap, _ := converters.NewBalanceConverter(18)
33-
scrsProc := newSmartContractResultsProcessor(pubKeyConverter, &mock.MarshalizerMock{}, &mock.HasherMock{}, parser, ap)
34+
scrsProc := newSmartContractResultsProcessor(pubKeyConverter, &mock.MarshalizerMock{}, &mock.HasherMock{}, parser, ap, 0)
3435

3536
nonce := uint64(10)
3637
txHash := []byte("txHash")

0 commit comments

Comments
 (0)