Skip to content
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
5 changes: 3 additions & 2 deletions cmd/evmconnect.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,15 @@ import (
"github.com/hyperledger/firefly-common/pkg/log"
"github.com/hyperledger/firefly-evmconnect/internal/ethereum"
fftmcmd "github.com/hyperledger/firefly-transaction-manager/cmd"
"github.com/hyperledger/firefly-transaction-manager/pkg/ffcapi"
"github.com/hyperledger/firefly-transaction-manager/pkg/fftm"
txhandlerfactory "github.com/hyperledger/firefly-transaction-manager/pkg/txhandler/registry"
"github.com/hyperledger/firefly-transaction-manager/pkg/txhandler/simple"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)

type EthereumConnector ethereum.Connector

var sigs = make(chan os.Signal, 1)

var rootCmd = &cobra.Command{
Expand Down Expand Up @@ -77,7 +78,7 @@ func InitConfig() {
txhandlerfactory.RegisterHandler(&simple.TransactionHandlerFactory{})
}

func NewEthereumConnector(ctx context.Context, conf config.Section) (cc ffcapi.API, err error) {
func NewEthereumConnector(ctx context.Context, conf config.Section) (EthereumConnector, error) {
return ethereum.NewEthereumConnector(ctx, conf)
}

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.23.0
require (
github.com/gorilla/mux v1.8.1
github.com/hashicorp/golang-lru v1.0.2
github.com/hyperledger/firefly-common v1.5.5
github.com/hyperledger/firefly-common v1.5.6-0.20250630201730-e234335c0381
github.com/hyperledger/firefly-signer v1.1.21
github.com/hyperledger/firefly-transaction-manager v1.4.0
github.com/sirupsen/logrus v1.9.3
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpO
github.com/huandu/xstrings v1.3.3/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
github.com/huandu/xstrings v1.4.0 h1:D17IlohoQq4UcpqD7fDk80P7l+lwAmlFaBHgOipl2FU=
github.com/huandu/xstrings v1.4.0/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
github.com/hyperledger/firefly-common v1.5.5 h1:UaANgBIT0aBvAk0Yt+Qrn6qXxpwNIrFfwnW3EBivrQs=
github.com/hyperledger/firefly-common v1.5.5/go.mod h1:1Xawm5PUhxT7k+CL/Kr3i1LE3cTTzoQwZMLimvlW8rs=
github.com/hyperledger/firefly-common v1.5.6-0.20250630201730-e234335c0381 h1:4mkvcaVwq9bopPQ7ZNfJqFiN2QA32cPSGUHSyEGSFno=
github.com/hyperledger/firefly-common v1.5.6-0.20250630201730-e234335c0381/go.mod h1:1Xawm5PUhxT7k+CL/Kr3i1LE3cTTzoQwZMLimvlW8rs=
github.com/hyperledger/firefly-signer v1.1.21 h1:r7cTOw6e/6AtiXLf84wZy6Z7zppzlc191HokW2hv4N4=
github.com/hyperledger/firefly-signer v1.1.21/go.mod h1:axrlSQeKrd124UdHF5L3MkTjb5DeTcbJxJNCZ3JmcWM=
github.com/hyperledger/firefly-transaction-manager v1.4.0 h1:l9DCizLTohKtKec5dewNlydhAeko1/DmTfCRF8le9m0=
Expand Down
38 changes: 20 additions & 18 deletions internal/ethereum/ethereum.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,12 @@ type ethConnector struct {
txCache *lru.Cache
}

func NewEthereumConnector(ctx context.Context, conf config.Section) (cc ffcapi.API, err error) {
type Connector interface {
ffcapi.API
RPC() rpcbackend.RPC
}

func NewEthereumConnector(ctx context.Context, conf config.Section) (cc Connector, err error) {
c := &ethConnector{
eventStreams: make(map[fftypes.UUID]*eventStream),
catchupPageSize: conf.GetInt64(EventsCatchupPageSize),
Expand All @@ -70,23 +75,9 @@ func NewEthereumConnector(ctx context.Context, conf config.Section) (cc ffcapi.A
retry: &retry.Retry{},
}

if !conf.IsSet(DeprecatedRetryInitDelay) || (conf.IsSet(DeprecatedRetryInitDelay) && conf.IsSet(RetryInitDelay)) {
c.retry.InitialDelay = conf.GetDuration(RetryInitDelay)
} else {
c.retry.InitialDelay = conf.GetDuration(DeprecatedRetryInitDelay)
}

if !conf.IsSet(DeprecatedRetryFactor) || (conf.IsSet(DeprecatedRetryFactor) && conf.IsSet(RetryFactor)) {
c.retry.Factor = conf.GetFloat64(RetryFactor)
} else {
c.retry.Factor = conf.GetFloat64(DeprecatedRetryFactor)
}

if !conf.IsSet(DeprecatedRetryMaxDelay) || (conf.IsSet(DeprecatedRetryMaxDelay) && conf.IsSet(RetryMaxDelay)) {
c.retry.MaximumDelay = conf.GetDuration(RetryMaxDelay)
} else {
c.retry.MaximumDelay = conf.GetDuration(DeprecatedRetryMaxDelay)
}
c.retry.InitialDelay = withDeprecatedConfFallback(conf, conf.GetDuration, DeprecatedRetryInitDelay, RetryInitDelay)
c.retry.Factor = withDeprecatedConfFallback(conf, conf.GetFloat64, DeprecatedRetryFactor, RetryFactor)
c.retry.MaximumDelay = withDeprecatedConfFallback(conf, conf.GetDuration, DeprecatedRetryMaxDelay, RetryMaxDelay)

if c.catchupThreshold < c.catchupPageSize {
log.L(ctx).Warnf("Catchup threshold %d must be at least as large as the catchup page size %d (overridden to %d)", c.catchupThreshold, c.catchupPageSize, c.catchupPageSize)
Expand Down Expand Up @@ -152,6 +143,10 @@ func NewEthereumConnector(ctx context.Context, conf config.Section) (cc ffcapi.A
return c, nil
}

func (c *ethConnector) RPC() rpcbackend.RPC {
return c.backend
}

// WaitClosed can be called after cancelling all the contexts, to wait for everything to close down
func (c *ethConnector) WaitClosed() {
if c.blockListener != nil {
Expand All @@ -161,3 +156,10 @@ func (c *ethConnector) WaitClosed() {
<-s.streamLoopDone
}
}

func withDeprecatedConfFallback[T any](conf config.Section, getter func(string) T, deprecatedKey, newKey string) T {
if !conf.IsSet(deprecatedKey) || (conf.IsSet(deprecatedKey) && conf.IsSet(newKey)) {
return getter(newKey)
}
return getter(deprecatedKey)
}
25 changes: 25 additions & 0 deletions internal/ethereum/ethereum_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
)

func strPtr(s string) *string { return &s }
Expand Down Expand Up @@ -59,6 +60,8 @@ func newTestConnectorWithNoBlockerFilterDefaultMocks(t *testing.T, confSetup ...
ctx, done := context.WithCancel(context.Background())
cc, err := NewEthereumConnector(ctx, conf)
assert.NoError(t, err)
assert.NotNil(t, cc.RPC())

c := cc.(*ethConnector)
c.backend = mRPC
c.blockListener.backend = mRPC
Expand Down Expand Up @@ -193,3 +196,25 @@ func TestNewEthereumConnectorConfig(t *testing.T) {
assert.Equal(t, 4.0, cc.(*ethConnector).retry.Factor)
assert.Equal(t, 30*time.Second, cc.(*ethConnector).retry.MaximumDelay)
}

func TestWithDeprecatedConfFallback(t *testing.T) {

config.RootConfigReset()
conf := config.RootSection("tdcf")
conf.AddKnownKey("deprecatedKey")
conf.AddKnownKey("newKey")

conf.Set("deprecatedKey", 1111)
require.Equal(t, 1111, withDeprecatedConfFallback(conf, conf.GetInt, "deprecatedKey", "newKey"))

conf.Set("newKey", 2222)
require.Equal(t, 2222, withDeprecatedConfFallback(conf, conf.GetInt, "deprecatedKey", "newKey"))

config.RootConfigReset()
conf = config.RootSection("tdcf")
conf.AddKnownKey("deprecatedKey")
conf.AddKnownKey("newKey")
conf.Set("newKey", 2222)
require.Equal(t, 2222, withDeprecatedConfFallback(conf, conf.GetInt, "deprecatedKey", "newKey"))

}