Skip to content

Commit 710fe3a

Browse files
authored
Merge pull request #74 from Chengxuan/config-support
Fixing support for legacy configs
2 parents d946156 + ac3579a commit 710fe3a

File tree

9 files changed

+75
-18
lines changed

9 files changed

+75
-18
lines changed

config.md

+49-2
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,54 @@
174174

175175
|Key|Description|Type|Default Value|
176176
|---|-----------|----|-------------|
177-
|name|Deprecated: Please use 'transactions.handler.name' instead|`string`|`<nil>`
177+
|name|Deprecated: Please use 'transactions.handler.name' instead|`string`|`simple`
178+
179+
## policyengine.simple
180+
181+
|Key|Description|Type|Default Value|
182+
|---|-----------|----|-------------|
183+
|fixedGasPrice|Deprecated: Please use 'transactions.handler.simple.fixedGasPrice' instead|Raw JSON|`<nil>`
184+
|resubmitInterval|Deprecated: Please use 'transactions.handler.simple.resubmitInterval' instead|[`time.Duration`](https://pkg.go.dev/time#Duration)|`<nil>`
185+
186+
## policyengine.simple.gasOracle
187+
188+
|Key|Description|Type|Default Value|
189+
|---|-----------|----|-------------|
190+
|connectionTimeout|The maximum amount of time that a connection is allowed to remain with no data transmitted|[`time.Duration`](https://pkg.go.dev/time#Duration)|`<nil>`
191+
|expectContinueTimeout|See [ExpectContinueTimeout in the Go docs](https://pkg.go.dev/net/http#Transport)|[`time.Duration`](https://pkg.go.dev/time#Duration)|`<nil>`
192+
|headers|Adds custom headers to HTTP requests|`map[string]string`|`<nil>`
193+
|idleTimeout|The max duration to hold a HTTP keepalive connection between calls|[`time.Duration`](https://pkg.go.dev/time#Duration)|`<nil>`
194+
|maxIdleConns|The max number of idle connections to hold pooled|`int`|`<nil>`
195+
|method|Deprecated: Please use 'transactions.handler.simple.gasOracle.method' instead|`string`|`<nil>`
196+
|mode|Deprecated: Please use 'transactions.handler.simple.gasOracle.mode' instead|'connector', 'restapi', 'fixed', or 'disabled'|`<nil>`
197+
|passthroughHeadersEnabled|Enable passing through the set of allowed HTTP request headers|`boolean`|`<nil>`
198+
|queryInterval|Deprecated: Please use 'transactions.handler.simple.gasOracle.queryInterval' instead|[`time.Duration`](https://pkg.go.dev/time#Duration)|`<nil>`
199+
|requestTimeout|The maximum amount of time that a request is allowed to remain open|[`time.Duration`](https://pkg.go.dev/time#Duration)|`<nil>`
200+
|template|Deprecated: Please use 'transactions.handler.simple.gasOracle.template' instead|[Go Template](https://pkg.go.dev/text/template) `string`|`<nil>`
201+
|tlsHandshakeTimeout|The maximum amount of time to wait for a successful TLS handshake|[`time.Duration`](https://pkg.go.dev/time#Duration)|`<nil>`
202+
|url|Deprecated: Please use 'transactions.handler.simple.gasOracle.url' instead|`string`|`<nil>`
203+
204+
## policyengine.simple.gasOracle.auth
205+
206+
|Key|Description|Type|Default Value|
207+
|---|-----------|----|-------------|
208+
|password|Password|`string`|`<nil>`
209+
|username|Username|`string`|`<nil>`
210+
211+
## policyengine.simple.gasOracle.proxy
212+
213+
|Key|Description|Type|Default Value|
214+
|---|-----------|----|-------------|
215+
|url|Deprecated: Please use 'transactions.handler.simple.gasOracle.proxy.url' instead|`string`|`<nil>`
216+
217+
## policyengine.simple.gasOracle.retry
218+
219+
|Key|Description|Type|Default Value|
220+
|---|-----------|----|-------------|
221+
|count|The maximum number of times to retry|`int`|`<nil>`
222+
|enabled|Enables retries|`boolean`|`<nil>`
223+
|initWaitTime|The initial retry delay|[`time.Duration`](https://pkg.go.dev/time#Duration)|`<nil>`
224+
|maxWaitTime|The maximum retry delay|[`time.Duration`](https://pkg.go.dev/time#Duration)|`<nil>`
178225

179226
## policyloop
180227

@@ -202,7 +249,7 @@
202249

203250
|Key|Description|Type|Default Value|
204251
|---|-----------|----|-------------|
205-
|name|The name of the transaction handler to use|`string`|`simple`
252+
|name|The name of the transaction handler to use|`string`|`<nil>`
206253

207254
## transactions.handler.simple
208255

internal/tmconfig/tmconfig.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ func setDefaults() {
109109
viper.SetDefault(string(MetricsPath), "/metrics")
110110

111111
viper.SetDefault(string(APIPassthroughHeaders), []string{})
112-
viper.SetDefault(string(TransactionHandlerName), "simple")
112+
viper.SetDefault(string(DeprecatedPolicyEngineName), "simple")
113113

114114
// Deprecated default values for transaction handling configurations
115115
viper.SetDefault(string(DeprecatedTransactionsMaxInFlight), 100)

pkg/fftm/address_management_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import (
2929
)
3030

3131
func TestBalanceOK(t *testing.T) {
32-
3332
_, m, cancel := newTestManager(t)
3433
defer cancel()
3534
m.Start()

pkg/fftm/manager.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ func (m *manager) initServices(ctx context.Context) (err error) {
119119
}
120120

121121
// check whether a policy engine name is provided
122-
if config.GetString(tmconfig.DeprecatedPolicyEngineName) != "" {
123-
log.L(ctx).Warnf("The 'policyengine.name' config key has been deprecated. Please use 'transactions.handler.name' instead")
122+
if config.GetString(tmconfig.TransactionHandlerName) == "" {
123+
log.L(ctx).Warnf("The 'policyengine' config key has been deprecated. Please use 'transactions.handler' instead")
124124
m.txHandler, err = txRegistry.NewTransactionHandler(ctx, tmconfig.DeprecatedPolicyEngineBaseConfig, config.GetString(tmconfig.DeprecatedPolicyEngineName))
125125
} else {
126126
// if not, fall back to use the deprecated policy engine

pkg/fftm/manager_test.go

+3
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ func strPtr(s string) *string { return &s }
4848
func testManagerCommonInit(t *testing.T, withMetrics bool) string {
4949

5050
InitConfig()
51+
viper.SetDefault(string(tmconfig.TransactionHandlerName), "simple")
5152
txRegistry.RegisterHandler(&simple.TransactionHandlerFactory{})
5253
tmconfig.TransactionHandlerBaseConfig.SubSection("simple").SubSection(simple.GasOracleConfig).Set(simple.GasOracleMode, simple.GasOracleModeDisabled)
5354

@@ -267,6 +268,8 @@ func TestNewManagerWithMetrics(t *testing.T) {
267268
func TestNewManagerWithMetricsBadConfig(t *testing.T) {
268269

269270
tmconfig.Reset()
271+
viper.SetDefault(string(tmconfig.TransactionHandlerName), "simple")
272+
270273
tmconfig.MetricsConfig.Set("enabled", true)
271274
tmconfig.MetricsConfig.Set(httpserver.HTTPConfAddress, "::::")
272275
dir, err := ioutil.TempDir("", "ldb_*")

pkg/txhandler/registry/registry.go

+2-9
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,7 @@ type Factory interface {
4545
func RegisterHandler(factory Factory) string {
4646
name := factory.Name()
4747
txHandlers[name] = factory
48-
49-
// check whether a policy engine name is provided
50-
if config.GetString(tmconfig.DeprecatedPolicyEngineName) != "" {
51-
factory.InitConfig(tmconfig.DeprecatedPolicyEngineBaseConfig.SubSection(name))
52-
} else {
53-
// if not, use the new transaction handler configurations
54-
factory.InitConfig(tmconfig.TransactionHandlerBaseConfig.SubSection(name))
55-
56-
}
48+
// init the new transaction handler configurations
49+
factory.InitConfig(tmconfig.TransactionHandlerBaseConfig.SubSection(name))
5750
return name
5851
}

pkg/txhandler/simple/config.go

+13
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121

2222
"github.com/hyperledger/firefly-common/pkg/config"
2323
"github.com/hyperledger/firefly-common/pkg/ffresty"
24+
"github.com/hyperledger/firefly-transaction-manager/internal/tmconfig"
2425
)
2526

2627
const (
@@ -78,4 +79,16 @@ func (f *TransactionHandlerFactory) InitConfig(conf config.Section) {
7879
gasOracleConfig.AddKnownKey(GasOracleMode, defaultGasOracleMode)
7980
gasOracleConfig.AddKnownKey(GasOracleQueryInterval, defaultGasOracleQueryInterval)
8081
gasOracleConfig.AddKnownKey(GasOracleTemplate)
82+
83+
// Init the deprecated policy engine config in case people are still using them
84+
legacyConfig := tmconfig.DeprecatedPolicyEngineBaseConfig.SubSection(f.Name())
85+
legacyConfig.AddKnownKey(FixedGasPrice)
86+
legacyConfig.AddKnownKey(ResubmitInterval, defaultResubmitInterval)
87+
88+
legacyGasOracleConfig := legacyConfig.SubSection(GasOracleConfig)
89+
ffresty.InitConfig(legacyGasOracleConfig)
90+
legacyGasOracleConfig.AddKnownKey(GasOracleMethod, defaultGasOracleMethod)
91+
legacyGasOracleConfig.AddKnownKey(GasOracleMode, defaultGasOracleMode)
92+
legacyGasOracleConfig.AddKnownKey(GasOracleQueryInterval, defaultGasOracleQueryInterval)
93+
legacyGasOracleConfig.AddKnownKey(GasOracleTemplate)
8194
}

pkg/txhandler/simple/simple_transaction_hander_test.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ import (
5353
func newTestTransactionHandlerFactory(t *testing.T) (*TransactionHandlerFactory, *txhandler.Toolkit, *ffcapimocks.API, config.Section) {
5454
tmconfig.Reset()
5555
conf := config.RootSection("unittest.simple")
56+
viper.SetDefault(string(tmconfig.TransactionHandlerName), "simple")
5657

5758
f := &TransactionHandlerFactory{}
5859
f.InitConfig(conf)
@@ -74,6 +75,7 @@ func newTestTransactionHandlerFactory(t *testing.T) (*TransactionHandlerFactory,
7475
func newTestTransactionHandlerFactoryWithFilePersistence(t *testing.T) (*TransactionHandlerFactory, *txhandler.Toolkit, *ffcapimocks.API, config.Section, func()) {
7576
tmconfig.Reset()
7677
conf := config.RootSection("unittest.simple")
78+
viper.SetDefault(string(tmconfig.TransactionHandlerName), "simple")
7779

7880
f := &TransactionHandlerFactory{}
7981
f.InitConfig(conf)
@@ -111,7 +113,7 @@ func newTestTransactionHandler(t *testing.T) txhandler.TransactionHandler {
111113

112114
func TestSupportDeprecatedPolicyEngineConfiguration(t *testing.T) {
113115
f, _, _, conf := newTestTransactionHandlerFactory(t)
114-
viper.SetDefault(string(tmconfig.DeprecatedPolicyEngineName), "simple")
116+
viper.SetDefault(string(tmconfig.TransactionHandlerName), "")
115117
viper.SetDefault(string(tmconfig.DeprecatedTransactionsMaxInFlight), 23412412)
116118

117119
conf.Set(FixedGasPrice, `12345`)

pkg/txhandler/simple/simple_transaction_handler.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ func (f *TransactionHandlerFactory) NewTransactionHandler(ctx context.Context, c
8080
inflightUpdate: make(chan bool, 1),
8181
}
8282

83-
// check whether a policy engine name is provided
84-
if config.GetString(tmconfig.DeprecatedPolicyEngineName) != "" {
83+
// check whether we are using deprecated configuration
84+
if config.GetString(tmconfig.TransactionHandlerName) == "" {
8585
log.L(ctx).Warnf("Initializing transaction handler with deprecated configurations. Please use 'transactions.handler' instead")
8686
sth.nonceStateTimeout = config.GetDuration(tmconfig.DeprecatedTransactionsNonceStateTimeout)
8787
sth.maxInFlight = config.GetInt(tmconfig.DeprecatedTransactionsMaxInFlight)

0 commit comments

Comments
 (0)