-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
txmgr: add rpc api getters/setters (#10897)
* Add txmgr rpc api * Update mock TxManager * Use parameterized tests to remove redundant code * Add txmgr.cfgLock to protect values configurable at runtime * txmgr: use generic API() method on interface to allow custom rpc apis * txmgr: re-generate mocks * txmgr: use atomics for Config vals that can be modified via rpc * txmgr: use pointer for SimpleTxManager.cfg * txmgr: remove extraneous code * txmgr: cleanup ctx input arg in rpc methods
- Loading branch information
1 parent
376b11c
commit 549b52e
Showing
12 changed files
with
338 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package txmgr | ||
|
||
import ( | ||
"context" | ||
"math/big" | ||
"time" | ||
|
||
"github.com/ethereum/go-ethereum/log" | ||
) | ||
|
||
type SimpleTxmgrAPI struct { | ||
mgr *SimpleTxManager | ||
l log.Logger | ||
} | ||
|
||
func (a *SimpleTxmgrAPI) GetMinBaseFee(_ context.Context) *big.Int { | ||
return a.mgr.GetMinBaseFee() | ||
} | ||
|
||
func (a *SimpleTxmgrAPI) SetMinBaseFee(_ context.Context, val *big.Int) { | ||
a.mgr.SetMinBaseFee(val) | ||
} | ||
|
||
func (a *SimpleTxmgrAPI) GetPriorityFee(_ context.Context) *big.Int { | ||
return a.mgr.GetPriorityFee() | ||
} | ||
|
||
func (a *SimpleTxmgrAPI) SetPriorityFee(_ context.Context, val *big.Int) { | ||
a.mgr.SetPriorityFee(val) | ||
} | ||
|
||
func (a *SimpleTxmgrAPI) GetMinBlobFee(_ context.Context) *big.Int { | ||
return a.mgr.GetMinBlobFee() | ||
} | ||
|
||
func (a *SimpleTxmgrAPI) SetMinBlobFee(_ context.Context, val *big.Int) { | ||
a.mgr.SetMinBlobFee(val) | ||
} | ||
|
||
func (a *SimpleTxmgrAPI) GetFeeThreshold(_ context.Context) *big.Int { | ||
return a.mgr.GetFeeThreshold() | ||
} | ||
|
||
func (a *SimpleTxmgrAPI) SetFeeThreshold(_ context.Context, val *big.Int) { | ||
a.mgr.SetFeeThreshold(val) | ||
} | ||
|
||
func (a *SimpleTxmgrAPI) GetBumpFeeRetryTime(_ context.Context) time.Duration { | ||
return a.mgr.GetBumpFeeRetryTime() | ||
} | ||
|
||
func (a *SimpleTxmgrAPI) SetBumpFeeRetryTime(_ context.Context, val time.Duration) { | ||
a.mgr.SetBumpFeeRetryTime(val) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package txmgr | ||
|
||
import ( | ||
"fmt" | ||
"math/big" | ||
"testing" | ||
|
||
oprpc "github.com/ethereum-optimism/optimism/op-service/rpc" | ||
"github.com/ethereum/go-ethereum/rpc" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestTxmgrRPC(t *testing.T) { | ||
minBaseFee := big.NewInt(1000) | ||
priorityFee := big.NewInt(2000) | ||
minBlobFee := big.NewInt(3000) | ||
feeThreshold := big.NewInt(4000) | ||
|
||
cfg := Config{} | ||
cfg.MinBaseFee.Store(minBaseFee) | ||
cfg.MinTipCap.Store(priorityFee) | ||
cfg.MinBlobTxFee.Store(minBlobFee) | ||
cfg.FeeLimitThreshold.Store(feeThreshold) | ||
|
||
h := newTestHarnessWithConfig(t, &cfg) | ||
|
||
appVersion := "test" | ||
server := oprpc.NewServer( | ||
"127.0.0.1", | ||
0, | ||
appVersion, | ||
oprpc.WithAPIs([]rpc.API{ | ||
h.mgr.API(), | ||
}), | ||
) | ||
require.NoError(t, server.Start()) | ||
defer func() { | ||
_ = server.Stop() | ||
}() | ||
|
||
rpcClient, err := rpc.Dial(fmt.Sprintf("http://%s", server.Endpoint())) | ||
require.NoError(t, err) | ||
|
||
type tcase struct { | ||
rpcMethod string | ||
value *big.Int | ||
} | ||
|
||
cases := []tcase{ | ||
{"MinBaseFee", big.NewInt(1001)}, | ||
{"PriorityFee", big.NewInt(2001)}, | ||
{"MinBlobFee", big.NewInt(3001)}, | ||
{"FeeThreshold", big.NewInt(4001)}, | ||
} | ||
|
||
for _, tc := range cases { | ||
t.Run(tc.rpcMethod, func(t *testing.T) { | ||
var res *big.Int | ||
require.NoError(t, rpcClient.Call(&res, "txmgr_set"+tc.rpcMethod, tc.value)) | ||
require.NoError(t, rpcClient.Call(&res, "txmgr_get"+tc.rpcMethod)) | ||
require.Equal(t, tc.value, res) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.