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

Merge feat/v3 #271

Merged
merged 5 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Set up Go 1.x
uses: actions/setup-go@v3
with:
go-version: 1.17.6
go-version: 1.20.7
id: go

- name: Check out code into the Go module directory
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/code-coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- name: Set up Go 1.x
uses: actions/setup-go@v3
with:
go-version: 1.17.6
go-version: 1.20.7
id: go

- name: Check out code into the Go module directory
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/create_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: Set up Go 1.x
uses: actions/setup-go@v3
with:
go-version: 1.17.6
go-version: 1.20.7
id: go

- name: Check out code into the Go module directory
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ jobs:
steps:
- uses: actions/setup-go@v3
with:
go-version: 1.17.6
go-version: 1.20.7
- uses: actions/checkout@v3
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
version: v1.45.2
version: v1.53.2

# Optional: working directory, useful for monorepos
# working-directory: somedir
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pr-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: Set up Go 1.x
uses: actions/setup-go@v3
with:
go-version: 1.17.6
go-version: 1.20.7
id: go

- name: Check out code
Expand Down
6 changes: 1 addition & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@ build-cmd:
(cd cmd && go build)

clean-test:
go clean -testcache ./...

clean: clean-test
go clean -cache ./...
go clean ./...
go clean -testcache

test: clean-test
go test ./...
Expand Down
8 changes: 4 additions & 4 deletions api/gin/webServer.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ var log = logger.GetOrCreate("api")
type ArgsNewWebServer struct {
Facade shared.FacadeHandler
ApiConfig config.ApiRoutesConfig
AntiFloodConfig config.AntifloodConfig
AntiFloodConfig config.WebAntifloodConfig
}

type webServer struct {
sync.RWMutex
facade shared.FacadeHandler
apiConfig config.ApiRoutesConfig
antiFloodConfig config.AntifloodConfig
antiFloodConfig config.WebAntifloodConfig
httpServer chainShared.HttpServerCloser
groups map[string]shared.GroupHandler
cancelFunc func()
Expand Down Expand Up @@ -116,9 +116,9 @@ func (ws *webServer) StartHttpServer() error {

ws.registerRoutes(engine)

server := &http.Server{Addr: ws.facade.RestApiInterface(), Handler: engine}
serverInstance := &http.Server{Addr: ws.facade.RestApiInterface(), Handler: engine}
log.Debug("creating gin web sever", "interface", ws.facade.RestApiInterface())
ws.httpServer, err = NewHttpServer(server)
ws.httpServer, err = NewHttpServer(serverInstance)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion api/gin/webServer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func createMockArgsNewWebServer() ArgsNewWebServer {
},
APIPackages: make(map[string]config.APIPackageConfig),
},
AntiFloodConfig: config.AntifloodConfig{
AntiFloodConfig: config.WebAntifloodConfig{
Enabled: true,
WebServer: config.WebServerAntifloodConfig{
SimultaneousRequests: 1,
Expand Down
6 changes: 3 additions & 3 deletions clients/batchValidator/batchValidator.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"io"
"net/http"
"time"

Expand Down Expand Up @@ -115,7 +115,7 @@ func (bv *batchValidator) doRequestReturningBytes(batch []byte, ctx context.Cont
return nil, err
}
if response.StatusCode == http.StatusBadRequest && response.Body != http.NoBody {
data, _ := ioutil.ReadAll(response.Body)
data, _ := io.ReadAll(response.Body)
badResponse := &microserviceBadRequestBody{}
err = json.Unmarshal(data, badResponse)
if err != nil {
Expand All @@ -131,7 +131,7 @@ func (bv *batchValidator) doRequestReturningBytes(batch []byte, ctx context.Cont
_ = response.Body.Close()
}()

body, err := ioutil.ReadAll(response.Body)
body, err := io.ReadAll(response.Body)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions clients/batchValidator/batchValidator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"io"
"math/big"
"net/http"
"net/http/httptest"
Expand Down Expand Up @@ -261,7 +261,7 @@ func TestBatchValidator_ValidateBatch(t *testing.T) {
_ = request.Body.Close()
}()

body, err := ioutil.ReadAll(request.Body)
body, err := io.ReadAll(request.Body)
require.Nil(t, err)
require.Equal(t, expectedJsonString, string(body))

Expand Down
4 changes: 2 additions & 2 deletions clients/gasManagement/gasStation.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"math/big"
"net/http"
"sync"
Expand Down Expand Up @@ -196,7 +196,7 @@ func (gs *gasStation) doRequestReturningBytes(ctx context.Context) ([]byte, erro
_ = response.Body.Close()
}()

body, err := ioutil.ReadAll(response.Body)
body, err := io.ReadAll(response.Body)
if err != nil {
return nil, err
}
Expand Down
9 changes: 7 additions & 2 deletions clients/multiversx/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"github.com/multiversx/mx-sdk-go/builders"
"github.com/multiversx/mx-sdk-go/core"
"github.com/multiversx/mx-sdk-go/data"
"github.com/multiversx/mx-sdk-go/interactors/nonceHandlerV1"
"github.com/multiversx/mx-sdk-go/interactors/nonceHandlerV2"
)

const (
Expand Down Expand Up @@ -73,7 +73,12 @@ func NewClient(args ClientArgs) (*client, error) {
return nil, err
}

nonceTxsHandler, err := nonceHandlerV1.NewNonceTransactionHandlerV1(args.Proxy, time.Second*time.Duration(args.IntervalToResendTxsInSeconds), true)
argNonceHandler := nonceHandlerV2.ArgsNonceTransactionsHandlerV2{
Proxy: args.Proxy,
IntervalToResend: time.Second * time.Duration(args.IntervalToResendTxsInSeconds),
Creator: &nonceHandlerV2.AddressNonceHandlerCreator{},
}
nonceTxsHandler, err := nonceHandlerV2.NewNonceTransactionHandlerV2(argNonceHandler)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion clients/multiversx/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type Proxy interface {

// NonceTransactionsHandler represents the interface able to handle the current nonce and the transactions resend mechanism
type NonceTransactionsHandler interface {
GetNonce(ctx context.Context, address core.AddressHandler) (uint64, error)
ApplyNonceAndGasPrice(ctx context.Context, address core.AddressHandler, tx *transaction.FrontendTransaction) error
SendTransaction(ctx context.Context, tx *transaction.FrontendTransaction) (string, error)
Close() error
}
Expand Down
12 changes: 5 additions & 7 deletions clients/multiversx/transactionHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,6 @@ func (txHandler *transactionHandler) signTransaction(ctx context.Context, builde
return nil, err
}

nonce, err := txHandler.nonceTxHandler.GetNonce(context.Background(), txHandler.relayerAddress)
if err != nil {
return nil, err
}

dataBytes, err := builder.ToDataBytes()
if err != nil {
return nil, err
Expand All @@ -54,14 +49,17 @@ func (txHandler *transactionHandler) signTransaction(ctx context.Context, builde
ChainID: networkConfig.ChainID,
Version: networkConfig.MinTransactionVersion,
GasLimit: gasLimit,
GasPrice: networkConfig.MinGasPrice,
Nonce: nonce,
Data: dataBytes,
Sender: txHandler.relayerAddress.AddressAsBech32String(),
Receiver: txHandler.multisigAddressAsBech32,
Value: "0",
}

err = txHandler.nonceTxHandler.ApplyNonceAndGasPrice(context.Background(), txHandler.relayerAddress, tx)
if err != nil {
return nil, err
}

err = txHandler.signTransactionWithPrivateKey(tx)
if err != nil {
return nil, err
Expand Down
13 changes: 8 additions & 5 deletions clients/multiversx/transactionHandler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ func TestTransactionHandler_SendTransactionReturnHash(t *testing.T) {
expectedErr := errors.New("expected error in get nonce")
txHandlerInstance := createTransactionHandlerWithMockComponents()
txHandlerInstance.nonceTxHandler = &bridgeTests.NonceTransactionsHandlerStub{
GetNonceCalled: func(ctx context.Context, address core.AddressHandler) (uint64, error) {
return 0, expectedErr
ApplyNonceAndGasPriceCalled: func(ctx context.Context, address core.AddressHandler, tx *transaction.FrontendTransaction) error {
return expectedErr
},
}

Expand Down Expand Up @@ -140,12 +140,15 @@ func TestTransactionHandler_SendTransactionReturnHash(t *testing.T) {
}

txHandlerInstance.nonceTxHandler = &bridgeTests.NonceTransactionsHandlerStub{
GetNonceCalled: func(ctx context.Context, address core.AddressHandler) (uint64, error) {
ApplyNonceAndGasPriceCalled: func(ctx context.Context, address core.AddressHandler, tx *transaction.FrontendTransaction) error {
if address.AddressAsBech32String() == relayerAddress {
return nonce, nil
tx.Nonce = nonce
tx.GasPrice = minGasPrice

return nil
}

return 0, errors.New("unexpected address to fetch the nonce")
return errors.New("unexpected address to fetch the nonce")
},
SendTransactionCalled: func(ctx context.Context, tx *transaction.FrontendTransaction) (string, error) {
sendWasCalled = true
Expand Down
48 changes: 27 additions & 21 deletions cmd/bridge/config/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
MaxRetriesOnWasTransferProposed = 3
ProxyCacherExpirationSeconds = 600 # the caching time in seconds

# valid options for ProxyRestAPIEntityType are `observer` and `proxy`. Any other value will trigger an error.
# `observer` is useful when querying an observer, directly and `proxy` is useful when querying a squad's proxy
# valid options for ProxyRestAPIEntityType are "observer" and "proxy". Any other value will trigger an error.
# "observer" is useful when querying an observer, directly and "proxy" is useful when querying a squad's proxy (gateway)
ProxyRestAPIEntityType = "observer"
ProxyFinalityCheck = true
ProxyMaxNoncesDelta = 7 # the number of maximum blocks allowed to be "in front" of what the metachain has notarized
Expand All @@ -48,63 +48,70 @@
Port = "10010"
InitialPeerList = []
ProtocolID = "/erd/relay/1.0.0"
[AntifloodConfig]
[P2P.Transports]
QUICAddress = "" # optional QUIC address. If this transport should be activated, should be in this format: /ip4/0.0.0.0/udp/%d/quic-v1
WebSocketAddress = "" # optional WebSocket address. If this transport should be activated, should be in this format: /ip4/0.0.0.0/tcp/%d/ws
WebTransportAddress = "" # optional WebTransport address. If this transport should be activated, should be in this format: /ip4/0.0.0.0/udp/%d/quic-v1/webtransport
[P2P.Transports.TCP]
ListenAddress = "/ip4/0.0.0.0/tcp/%d" # TCP listen address
PreventPortReuse = false
[P2P.AntifloodConfig]
Enabled = true
NumConcurrentResolverJobs = 50
[Antiflood.FastReacting]
[P2P.AntifloodConfig.FastReacting]
IntervalInSeconds = 1
ReservedPercent = 20.0
[Antiflood.FastReacting.PeerMaxInput]
[P2P.AntifloodConfig.FastReacting.PeerMaxInput]
BaseMessagesPerInterval = 10
TotalSizePerInterval = 1048576 #1MB/s
[Antiflood.FastReacting.PeerMaxInput.IncreaseFactor]
[P2P.AntifloodConfig.FastReacting.PeerMaxInput.IncreaseFactor]
Threshold = 10 #if consensus size will exceed this value, then
Factor = 1.0 #increase the base value with [factor*consensus size]
[Antiflood.FastReacting.BlackList]
[P2P.AntifloodConfig.FastReacting.BlackList]
ThresholdNumMessagesPerInterval = 70
ThresholdSizePerInterval = 2097154 #2MB/s
NumFloodingRounds = 10
PeerBanDurationInSeconds = 300

[Antiflood.SlowReacting]
[P2P.AntifloodConfig.SlowReacting]
IntervalInSeconds = 30
ReservedPercent = 20.0
[Antiflood.SlowReacting.PeerMaxInput]
[P2P.AntifloodConfig.SlowReacting.PeerMaxInput]
BaseMessagesPerInterval = 400
TotalSizePerInterval = 10485760 #10MB/interval
[Antiflood.SlowReacting.PeerMaxInput.IncreaseFactor]
[P2P.AntifloodConfig.SlowReacting.PeerMaxInput.IncreaseFactor]
Threshold = 10 #if consensus size will exceed this value, then
Factor = 0.0 #increase the base value with [factor*consensus size]
[Antiflood.SlowReacting.BlackList]
[P2P.AntifloodConfig.SlowReacting.BlackList]
ThresholdNumMessagesPerInterval = 800
ThresholdSizePerInterval = 20971540 #20MB/interval
NumFloodingRounds = 2
PeerBanDurationInSeconds = 3600

[Antiflood.OutOfSpecs]
[P2P.AntifloodConfig.OutOfSpecs]
IntervalInSeconds = 1
ReservedPercent = 0.0
[Antiflood.OutOfSpecs.PeerMaxInput]
[P2P.AntifloodConfig.OutOfSpecs.PeerMaxInput]
BaseMessagesPerInterval = 140
TotalSizePerInterval = 4194304 #4MB/s
[Antiflood.OutOfSpecs.PeerMaxInput.IncreaseFactor]
[P2P.AntifloodConfig.OutOfSpecs.PeerMaxInput.IncreaseFactor]
Threshold = 0 #if consensus size will exceed this value, then
Factor = 0.0 #increase the base value with [factor*consensus size]
[Antiflood.OutOfSpecs.BlackList]
[P2P.AntifloodConfig.OutOfSpecs.BlackList]
ThresholdNumMessagesPerInterval = 200
ThresholdSizePerInterval = 6291456 #6MB/s
NumFloodingRounds = 2
PeerBanDurationInSeconds = 3600

[Antiflood.PeerMaxOutput]
[P2P.AntifloodConfig.PeerMaxOutput]
BaseMessagesPerInterval = 5
TotalSizePerInterval = 524288 #512KB/s

[Antiflood.Cache]
[P2P.AntifloodConfig.Cache]
Name = "Antiflood"
Capacity = 7000
Type = "LRU"
[Antiflood.Topic]
[P2P.AntifloodConfig.Topic]
DefaultMaxMessagesPerSec = 300 # default number of messages per interval for a topic
MaxMessages = [{ Topic = "EthereumToMultiversX_join", NumMessagesPerSec = 100 },
{ Topic = "EthereumToMultiversX_sign", NumMessagesPerSec = 100 }]
Expand All @@ -114,7 +121,6 @@
Type = "gogo protobuf"
SizeCheckDelta = 10
[Relayer.RoleProvider]
UsePolling = true
PollingIntervalInMillis = 60000 # 1 minute
[Relayer.StatusMetricsStorage]
[Relayer.StatusMetricsStorage.Cache]
Expand All @@ -141,9 +147,9 @@
LogFileLifeSpanInSec = 86400 # 24h
LogFileLifeSpanInMB = 1024 # 1GB

[Antiflood]
[WebAntiflood]
Enabled = true
[Antiflood.WebServer]
[WebAntiflood.WebServer]
# SimultaneousRequests represents the number of concurrent requests accepted by the web server
# this is a global throttler that acts on all http connections regardless of the originating source
SimultaneousRequests = 100
Expand Down
Loading