Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/sovereign #259

Draft
wants to merge 77 commits into
base: rc/spica-patch-relayedv3
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
6915b47
add sovereign header type
bogdan-rosianu Sep 28, 2023
96fb367
update core commit hash
bogdan-rosianu Sep 29, 2023
98a3964
update vm common commit hash
bogdan-rosianu Sep 29, 2023
d7fa746
Merge pull request #250 from multiversx/add-sovereign-header-type
mariusmihaic Oct 4, 2023
4cb6f3e
ignore scrs with no original tx hash
miiu96 Oct 5, 2023
225bc17
Merge pull request #251 from multiversx/ignore-scrs-no-original-tx-hash
mariusmihaic Oct 5, 2023
65fd3d9
remove metachain check
miiu96 Oct 6, 2023
57a0698
remove unit test
miiu96 Oct 11, 2023
2353c69
Merge pull request #252 from multiversx/remove-meta-check
mariusmihaic Jan 18, 2024
4a2cd80
Merge branch 'master' into merge-master-into-sovereign-30-jan-2024
mariusmihaic Jan 30, 2024
51a477e
FEAT: Update dependencies
mariusmihaic Jan 30, 2024
5eb1849
Merge pull request #262 from multiversx/merge-master-into-sovereign-3…
mariusmihaic Jan 30, 2024
fc27514
Merge branch 'rc/v1.7.next1' into merge-rc-v1-7-next-into-sovereign-1…
mariusmihaic May 14, 2024
92975ee
FIX: go mod
mariusmihaic May 14, 2024
62fd4fa
Merge pull request #279 from multiversx/merge-rc-v1-7-next-into-sover…
mariusmihaic May 15, 2024
2e10fe5
fix mappings
miiu96 Sep 5, 2024
17f4760
Merge pull request #295 from multiversx/fix-token-type-mappings
axenteoctavian Sep 6, 2024
7dc6e64
Merge branch 'master' into merge-master-into-feat-sovereign-9-oct-2024
mariusmihaic Oct 9, 2024
f37745c
FIX: go mod
mariusmihaic Oct 9, 2024
cbc1607
Merge branch 'rc/v1.7.next1' into merge-master-into-feat-sovereign-9-…
mariusmihaic Oct 9, 2024
7b5c180
FIX: go mod 2
mariusmihaic Oct 9, 2024
e1ddfdb
Merge pull request #299 from multiversx/merge-master-into-feat-sovere…
mariusmihaic Oct 11, 2024
8f3ff23
Merge branch 'rc/v1.7.next1' into merge-rc-1-7-next-into-sovereign-11…
axenteoctavian Nov 11, 2024
cbffebf
Merge pull request #303 from multiversx/merge-rc-1-7-next-into-sovere…
axenteoctavian Nov 11, 2024
641a7d1
run type components implementation
axenteoctavian Dec 3, 2024
92a42d0
sovereign flag
axenteoctavian Dec 4, 2024
b74e23e
tx hashes extractor implementation
axenteoctavian Dec 4, 2024
d4734ca
unit test fixes
axenteoctavian Dec 5, 2024
da7a422
reward tx data in run type components
axenteoctavian Dec 5, 2024
c1c08ba
reward tx data in run type components fixes
axenteoctavian Dec 5, 2024
81a630f
comments fixes
axenteoctavian Dec 5, 2024
d74e00e
Merge branch 'MX-16238-tx-hash-extractor' into MX-16244-transaction-s…
axenteoctavian Dec 5, 2024
6f08221
fixes after self review
axenteoctavian Dec 5, 2024
948c8fc
fixes after self review
axenteoctavian Dec 5, 2024
bba9bb6
Merge branch 'MX-16238-tx-hash-extractor' into MX-16244-transaction-s…
axenteoctavian Dec 5, 2024
d1394c4
integration tests fixes
axenteoctavian Dec 5, 2024
7ee3615
fix after review
axenteoctavian Dec 6, 2024
5c50ac4
fixes after review, refactor
axenteoctavian Dec 6, 2024
0623a0c
Merge branch 'MX-16233-sovereign-flag' into MX-16238-tx-hash-extractor
axenteoctavian Dec 6, 2024
a6f176c
fixes after review
axenteoctavian Dec 6, 2024
1c39a58
Merge branch 'MX-16238-tx-hash-extractor' into MX-16244-transaction-s…
axenteoctavian Dec 6, 2024
26330fc
fixes after review
axenteoctavian Dec 6, 2024
e3add43
fixes after review
axenteoctavian Dec 9, 2024
9ca95d3
renaming to Sovereign
axenteoctavian Dec 11, 2024
b30e362
Merge pull request #312 from multiversx/MX-16233-runtype-components
axenteoctavian Dec 11, 2024
417430d
Merge pull request #314 from multiversx/MX-16233-sovereign-flag
axenteoctavian Dec 11, 2024
4c6d164
Merge pull request #315 from multiversx/MX-16238-tx-hash-extractor
axenteoctavian Dec 11, 2024
23de514
Merge pull request #317 from multiversx/MX-16244-transaction-sender
axenteoctavian Dec 11, 2024
b91174c
Index incoming tokens
axenteoctavian Jan 23, 2025
706e1ff
removed some unused params
axenteoctavian Jan 23, 2025
57b1927
fixes after testing
axenteoctavian Jan 23, 2025
b5ebb3f
fixes and improvements after self review
axenteoctavian Jan 27, 2025
9659e73
fixes after self review
axenteoctavian Jan 27, 2025
372b46a
integration test fixes
axenteoctavian Jan 28, 2025
a110c90
unit test fixes
axenteoctavian Jan 28, 2025
a07073e
integration test fixes
axenteoctavian Jan 28, 2025
646fbbf
script.sh update
axenteoctavian Jan 28, 2025
86bc075
script.sh update
axenteoctavian Jan 28, 2025
e90867f
Merge remote-tracking branch 'origin/rc/spica-patch-relayedv3' into m…
axenteoctavian Jan 31, 2025
5d843ef
go mod for sovereign
axenteoctavian Jan 31, 2025
72295e5
integration tests fix from past commit
axenteoctavian Jan 31, 2025
68d88c1
Merge pull request #327 from multiversx/merge-spica-relayed-into-sove…
axenteoctavian Jan 31, 2025
73868f5
Merge branch 'feat/sovereign' into MX-16271-indexing-incoming-tokens
axenteoctavian Jan 31, 2025
87cc67f
fixes after review
axenteoctavian Feb 5, 2025
9d96aee
unit test fixes
axenteoctavian Feb 5, 2025
d2c8827
fixes after review
axenteoctavian Feb 6, 2025
2bf1792
fixes after review
axenteoctavian Feb 6, 2025
c54509b
fixes after review
axenteoctavian Feb 10, 2025
5cec770
fixes after review
axenteoctavian Feb 10, 2025
5978925
sovereign elastic indexer docker fixes
axenteoctavian Feb 10, 2025
3c1d628
fixes after review
axenteoctavian Feb 11, 2025
b09b8af
fixes after review
axenteoctavian Feb 12, 2025
7268376
Merge pull request #325 from multiversx/MX-16271-indexing-incoming-to…
axenteoctavian Feb 12, 2025
25a9d6a
Merge remote-tracking branch 'origin/rc/spica-patch-relayedv3' into m…
axenteoctavian Feb 17, 2025
89decf3
go.mod update for core
axenteoctavian Feb 17, 2025
ddd47d8
fix sovereign test after merge
axenteoctavian Feb 17, 2025
5ec3af7
Merge pull request #332 from multiversx/merge-spica-relayedv3-into-so…
axenteoctavian Feb 20, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions .github/workflows/deploy-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name: Publish Docker image
on:
release:
types: [published]
pull_request:

jobs:
push_to_registry:
Expand Down Expand Up @@ -31,24 +32,25 @@ jobs:
fi

- name: Log in to Docker Hub
if: ${{ github.event_name == 'release' && github.event.action == 'published' }}
uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
if: ${{ github.event_name == 'release' && github.event.action == 'published' }}
id: meta
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
images: multiversx/elastic-indexer
images: multiversx/sovereign-elastic-indexer

- name: Build and push Docker image
id: push
uses: docker/build-push-action@3b5e8027fcad23fda98b2e3ac259d8d67585f671
with:
context: .
file: ./Dockerfile
push: true
file: ./Dockerfile-sovereign
push: ${{ github.event_name == 'release' && github.event.action == 'published' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

26 changes: 26 additions & 0 deletions Dockerfile-sovereign
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
FROM golang:1.20.7 as builder

RUN apt-get update && apt-get install -y

WORKDIR /multiversx
COPY . .

WORKDIR /multiversx/cmd/elasticindexer

RUN go build -o elasticindexer

# ===== SECOND STAGE ======
FROM ubuntu:22.04
RUN apt-get update && apt-get install -y

RUN useradd -m -u 1000 appuser
USER appuser

COPY --from=builder --chown=appuser /multiversx/cmd/elasticindexer /multiversx

EXPOSE 22111

WORKDIR /multiversx

ENTRYPOINT ["./elasticindexer", "--sovereign"]
CMD ["--log-level", "*:DEBUG"]
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,16 @@ integration-tests-open-search:
INDEXER_IMAGE_NAME="elasticindexer"
INDEXER_IMAGE_TAG="latest"
DOCKER_FILE=Dockerfile
SOVEREIGN_DOCKER_FILE=Dockerfile-sovereign

docker-build:
docker build \
-t ${INDEXER_IMAGE_NAME}:${INDEXER_IMAGE_TAG} \
-f ${DOCKER_FILE} \
.

docker-sovereign-build:
docker build \
-t ${INDEXER_IMAGE_NAME}:${INDEXER_IMAGE_TAG} \
-f ${SOVEREIGN_DOCKER_FILE} \
.
78 changes: 78 additions & 0 deletions client/disabled/elasticClient.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package disabled

import (
"bytes"
"context"
)

type elasticClient struct{}

// NewDisabledElasticClient -
func NewDisabledElasticClient() *elasticClient {
return &elasticClient{}
}

// DoBulkRequest -
func (ec *elasticClient) DoBulkRequest(_ context.Context, _ *bytes.Buffer, _ string) error {
return nil
}

// DoQueryRemove -
func (ec *elasticClient) DoQueryRemove(_ context.Context, _ string, _ *bytes.Buffer) error {
return nil
}

// DoMultiGet -
func (ec *elasticClient) DoMultiGet(_ context.Context, _ []string, _ string, _ bool, _ interface{}) error {
return nil
}

// DoScrollRequest -
func (ec *elasticClient) DoScrollRequest(_ context.Context, _ string, _ []byte, _ bool, _ func(responseBytes []byte) error) error {
return nil
}

// DoCountRequest -
func (ec *elasticClient) DoCountRequest(_ context.Context, _ string, _ []byte) (uint64, error) {
return 0, nil
}

// UpdateByQuery -
func (ec *elasticClient) UpdateByQuery(_ context.Context, _ string, _ *bytes.Buffer) error {
return nil
}

// PutMappings -
func (ec *elasticClient) PutMappings(_ string, _ *bytes.Buffer) error {
return nil
}

// CheckAndCreateIndex -
func (ec *elasticClient) CheckAndCreateIndex(_ string) error {
return nil
}

// CheckAndCreateAlias -
func (ec *elasticClient) CheckAndCreateAlias(_ string, _ string) error {
return nil
}

// CheckAndCreateTemplate -
func (ec *elasticClient) CheckAndCreateTemplate(_ string, _ *bytes.Buffer) error {
return nil
}

// CheckAndCreatePolicy -
func (ec *elasticClient) CheckAndCreatePolicy(_ string, _ *bytes.Buffer) error {
return nil
}

// IsEnabled -
func (ec *elasticClient) IsEnabled() bool {
return false
}

// IsInterfaceNil - returns true if there is no value under the interface
func (ec *elasticClient) IsInterfaceNil() bool {
return ec == nil
}
31 changes: 31 additions & 0 deletions client/disabled/elasticClient_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package disabled

import (
"bytes"
"context"
"testing"

"github.com/multiversx/mx-chain-core-go/core/check"
"github.com/stretchr/testify/require"
)

func TestDisabledElasticClient_MethodsShouldNotPanic(t *testing.T) {
t.Parallel()

ec := NewDisabledElasticClient()
require.False(t, check.IfNil(ec))

require.NotPanics(t, func() {
_ = ec.DoBulkRequest(context.Background(), new(bytes.Buffer), "")
_ = ec.DoQueryRemove(context.Background(), "", new(bytes.Buffer))
_ = ec.DoMultiGet(context.Background(), make([]string, 0), "", true, nil)
_ = ec.DoScrollRequest(context.Background(), "", []byte(""), true, nil)
_, _ = ec.DoCountRequest(context.Background(), "", []byte(""))
_ = ec.UpdateByQuery(context.Background(), "", new(bytes.Buffer))
_ = ec.PutMappings("", new(bytes.Buffer))
_ = ec.CheckAndCreateIndex("")
_ = ec.CheckAndCreateAlias("", "")
_ = ec.CheckAndCreateTemplate("", new(bytes.Buffer))
_ = ec.CheckAndCreatePolicy("", new(bytes.Buffer))
})
}
11 changes: 11 additions & 0 deletions client/elasticClientCommon.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@ import (
"fmt"
"io"
"io/ioutil"
"math"
"net/http"
"net/url"
"strings"
"time"

"github.com/elastic/go-elasticsearch/v7/esapi"

"github.com/multiversx/mx-chain-es-indexer-go/data"
"github.com/multiversx/mx-chain-es-indexer-go/process/dataindexer"
)
Expand Down Expand Up @@ -268,3 +271,11 @@ func parseResponse(res *esapi.Response, dest interface{}, errorHandler responseE

return nil
}

// RetryBackOff returns elastic retry backoff duration
func RetryBackOff(attempt int) time.Duration {
d := time.Duration(math.Exp2(float64(attempt))) * time.Second
log.Debug("elastic: retry backoff", "attempt", attempt, "sleep duration", d)

return d
}
35 changes: 35 additions & 0 deletions client/mainChainElasticClient.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package client

import (
"github.com/multiversx/mx-chain-core-go/core/check"

"github.com/multiversx/mx-chain-es-indexer-go/process/dataindexer"
"github.com/multiversx/mx-chain-es-indexer-go/process/elasticproc"
)

type mainChainElasticClient struct {
elasticproc.DatabaseClientHandler
indexingEnabled bool
}

// NewMainChainElasticClient creates a new sovereign elastic client
func NewMainChainElasticClient(esClient elasticproc.DatabaseClientHandler, indexingEnabled bool) (*mainChainElasticClient, error) {
if check.IfNil(esClient) {
return nil, dataindexer.ErrNilDatabaseClient
}

return &mainChainElasticClient{
esClient,
indexingEnabled,
}, nil
}

// IsEnabled returns true if main chain elastic client is enabled
func (mcec *mainChainElasticClient) IsEnabled() bool {
return mcec.indexingEnabled
}

// IsInterfaceNil returns true if there is no value under the interface
func (mcec *mainChainElasticClient) IsInterfaceNil() bool {
return mcec == nil
}
42 changes: 42 additions & 0 deletions client/mainChainElasticClient_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package client

import (
"fmt"
"testing"

"github.com/elastic/go-elasticsearch/v7"
"github.com/stretchr/testify/require"

"github.com/multiversx/mx-chain-es-indexer-go/process/dataindexer"
)

func TestNewMainChainElasticClient(t *testing.T) {
t.Run("nil elastic client, should error", func(t *testing.T) {
mainChainESClient, err := NewMainChainElasticClient(nil, true)
require.Error(t, err, dataindexer.ErrNilDatabaseClient)
require.True(t, mainChainESClient.IsInterfaceNil())
})
t.Run("valid elastic client, should work", func(t *testing.T) {
esClient, err := NewElasticClient(elasticsearch.Config{
Addresses: []string{"http://localhost:9200"},
})
require.Nil(t, err)
require.NotNil(t, esClient)

mainChainESClient, err := NewMainChainElasticClient(esClient, true)
require.NoError(t, err)
require.Equal(t, "*client.mainChainElasticClient", fmt.Sprintf("%T", mainChainESClient))
})
}

func TestMainChainElasticClient_IsEnabled(t *testing.T) {
esClient, err := NewElasticClient(elasticsearch.Config{
Addresses: []string{"http://localhost:9200"},
})
require.Nil(t, err)
require.NotNil(t, esClient)

mainChainESClient, err := NewMainChainElasticClient(esClient, true)
require.NoError(t, err)
require.Equal(t, true, mainChainESClient.IsEnabled())
}
1 change: 1 addition & 0 deletions cmd/elasticindexer/config/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"receipts", "scresults", "accountsesdt", "accountsesdthistory", "epochinfo", "scdeploys", "tokens", "tags",
"logs", "delegators", "operations", "esdts", "values", "events"
]
esdt-prefix = ""
[config.address-converter]
length = 32
type = "bech32"
Expand Down
8 changes: 8 additions & 0 deletions cmd/elasticindexer/config/prefs.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,11 @@
username = ""
password = ""
bulk-request-max-size-in-bytes = 4194304 # 4MB

# Configuration for main chain elastic cluster
# Used by the sovereign chain indexer to index incoming new tokens properties
[config.main-chain-elastic-cluster]
enabled = true
url = "http://localhost:9201"
username = ""
password = ""
5 changes: 5 additions & 0 deletions cmd/elasticindexer/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,9 @@ var (
Name: "disable-ansi-color",
Usage: "Boolean option for disabling ANSI colors in the logging system.",
}
// sovereign defines a flag that specifies if the es instance should run for a sovereign chain
sovereign = cli.BoolFlag{
Name: "sovereign",
Usage: "If set to true, will use sovereign run type components",
}
)
9 changes: 6 additions & 3 deletions cmd/elasticindexer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ import (
"github.com/multiversx/mx-chain-core-go/core/check"
"github.com/multiversx/mx-chain-core-go/core/closing"
"github.com/multiversx/mx-chain-core-go/data/outport"
logger "github.com/multiversx/mx-chain-logger-go"
"github.com/multiversx/mx-chain-logger-go/file"
"github.com/urfave/cli"

"github.com/multiversx/mx-chain-es-indexer-go/config"
"github.com/multiversx/mx-chain-es-indexer-go/factory"
"github.com/multiversx/mx-chain-es-indexer-go/metrics"
"github.com/multiversx/mx-chain-es-indexer-go/process/wsindexer"
logger "github.com/multiversx/mx-chain-logger-go"
"github.com/multiversx/mx-chain-logger-go/file"
"github.com/urfave/cli"
)

var (
Expand Down Expand Up @@ -63,6 +64,7 @@ func main() {
logLevel,
logSaveFile,
disableAnsiColor,
sovereign,
}
app.Authors = []cli.Author{
{
Expand All @@ -86,6 +88,7 @@ func startIndexer(ctx *cli.Context) error {
if err != nil {
return fmt.Errorf("%w while loading the config file", err)
}
cfg.Sovereign = ctx.GlobalBool(sovereign.Name)

clusterCfg, err := loadClusterConfig(ctx.GlobalString(configurationPreferencesFile.Name))
if err != nil {
Expand Down
8 changes: 8 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package config
type Config struct {
Config struct {
AvailableIndices []string `toml:"available-indices"`
ESDTPrefix string `toml:"esdt-prefix"`
AddressConverter struct {
Length int `toml:"length"`
Type string `toml:"type"`
Expand All @@ -29,6 +30,7 @@ type Config struct {
LogsPath string `toml:"logs-path"`
} `toml:"logs"`
} `toml:"config"`
Sovereign bool
}

// ClusterConfig will hold the config for the Elasticsearch cluster
Expand All @@ -51,6 +53,12 @@ type ClusterConfig struct {
Password string `toml:"password"`
BulkRequestMaxSizeInBytes int `toml:"bulk-request-max-size-in-bytes"`
} `toml:"elastic-cluster"`
MainChainCluster struct {
Enabled bool `toml:"enabled"`
URL string `toml:"url"`
UserName string `toml:"username"`
Password string `toml:"password"`
} `toml:"main-chain-elastic-cluster"`
} `toml:"config"`
}

Expand Down
Loading