-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Updated chainio and signer READMEs + some code comments added gas oracle refactored txmgr module added geometric txmgr make fmt log -> logger in simple txmgr add TODO + rename constructor update geometric txmgr to use sync api gasoracle refactor chore: switch to pointer to gasoracle in geometric txmgr Also added some comments example: add example test for geometric txmgr fix(geometric_example_test): start anvil container refactor(geometric txmgr): delete gasoracle and add its methods to geometric txmgr directly make fmt fix(lint): remove no longer used variable hundred wip moving geometric to its own subdir simplify privatekey_wallet delete old moved files add geometric txmgr metrics interface + noop metrics docs: add default values in geometric txmgr params comment test(geometric txmgr): add first simple test for geometric txmgr test(geometric txmgr): add some basic tx sending tests feat(ecdsa): add KeyAndAddressFromHexKey helper function feat(geometric txmgr): add integration test scaffold with 1 simple tx sending test fix(geometric txmgr): remove unneeded mutex test(geometric txmgr): add parallel mining logic to fakeEthBackend.SendTransaction to test parallel sending of txs feat(geometrix txmgr): refactor queryTicketDuration to be a param instead of a fixed const refactor(txmgr test harness): refactor into a mining goroutine fix(geometric txmgr test): use mutex to get rid of race condition refactor(geometric txmgr params): made all params public fields feat(geometric txmgr test): added congestedBlocks field to test network congestion where txs need to get bumped also made tests run fast by setting txmgr's GetTxReceiptTickerDuration to 100ms instead of the default 3s fix(geometric txmgr): bug in ensureAnyTxBroadcasted ethereum.NotFound errors were not handled properly, causing txs to never get bumped feat(geometric txmgr test): added congested network test * fix(geometric txmgr test): race condition to set congested blocks * fix compilation errors from prev rebase * make fmt * fix(geometric txmgr): make ethBackend interface private * doc(geometri txmgr): add default GetTxReceiptTickerDuration param as comment * chore(geometric txmgr): remove no longer used GasPricePercentageMultiplier param * doc(geometrix txmgr): comment ProcessTransaction -> processTransaction Co-authored-by: Madhur Shrimal <[email protected]> * chore(geometric txmgr): move code around to make it cleaner * chore(geometric txmgr): use utils.WrapError everywhere instead of fmt.Errorf * doc(geometric txmgr): added comment saying that we (probably) can delete while iterating over go map * make fmt * make fmt * refactor(geometric txmgr): change gas/gastip params to use floats instead of percentages * docs(geometric txmgr): add comments for the ensureAnyTxBroadcasted/Confirmed fcts * fix(typo): READMD -> README * make fmt * refactor(geometric txmgr): simplify code by only calling ensureAnyTxBroadcasted for fireblock wallet * fix(geometric txmgr): revert to old (correct) code for catching timeout errors * make fmt * refactor(ecdsa/utils): use strings.TrimPrefix to trim 0x prefix * delete(metrics.go): duplicate file, no longer needed * refactor(geometric txmgr): rename fct with clearer name for self-documentation * doc(geometric txmgr): fix comment that was not true * doc(geometric txmgr): correct comment * test(geometric txmgr): add test for sending tx with incorrect nonce * test(geometric txmgr): added parallel test that sends nonces in reverse order * doc(geometric txmgr): add comment explaining that processTransaction is goroutine safe * chore(geometric txmgr): uncomment code that was commented while debugging --------- Co-authored-by: Madhur Shrimal <[email protected]>
- Loading branch information
1 parent
108520f
commit bdeff56
Showing
19 changed files
with
1,660 additions
and
247 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,30 @@ | ||
## ChainIO | ||
|
||
This module is used to facilitate reading/writing/subscribing to [eigenlayer core](./clients/elcontracts/) contracts and [avs registry](./clients/avsregistry/) contracts. | ||
|
||
To make it easier to understand the different structs in this package, and their hierarchical relationship, we describe each of them below: | ||
- geth's ethClient | ||
- eigensdk [ethClient](./clients/eth/client.go) | ||
- wraps geth's ethClient and adds convenience methods | ||
- [eigenlayerContractBindings](../contracts/bindings/) | ||
### Interacting with a json-rpc node | ||
|
||
We have a basic [ethClient](./clients/eth/client.go) which simply wraps geth's ethClient and adds some convenience methods. The Client interface is also implemented by [instrumentedClient](./clients/eth/instrumented_client.go) which adds metrics to the ethClient to conform to the node spec's [rpc metrics](https://docs.eigenlayer.xyz/eigenlayer/avs-guides/spec/metrics/metrics-prom-spec#rpc-metrics) requirements. | ||
|
||
|
||
### Building Transactions | ||
|
||
In order to facilitate reading/writing/subscribing to [eigenlayer core](./clients/elcontracts/) contracts and [avs registry](./clients/avsregistry/) contracts, we use geth's abigen created bindings for low-level interactions, as well as our own high-level clients with higher utility functions: | ||
- [Eigenlayer Contract Bindings](./clients/elcontracts/bindings.go) | ||
- generated by abigen | ||
- low level bindings to eigenlayer core contracts, which wrap our ethClient | ||
- [elContractsClient](./clients/eth/client.go) | ||
- wraps eigenlayerContractBindings and hides a little bit of the underlying complexity, which is not needed in 99% of cases. | ||
- abigen also doesn't create an interface for the bindings it generates, whereas elContractsClient has a well defined interface which we use to generate mocks to help with testing. | ||
- [ELChainReader](./clients/elcontracts/reader.go) / [ELChainWriter](./clients/elcontracts/writer.go) / [ELChainSubscriber](./clients/avsregistry/subscriber.go) | ||
- wraps elContractsClient and adds convenience methods | ||
- hides even more complexity than elContractsClient | ||
- wraps bindings and adds convenience methods | ||
- These structs should be the only ones used by AVS developers, apart from interacting with an ethClient directly to make direct json rpc calls such as waiting for a transaction receipt. | ||
|
||
A similar hierarchy applies for the avs registry contracts. | ||
There's a similar setup for the [avs registry](./clients/avsregistry/) contracts. | ||
|
||
### Signing, Sending, and Managing Transactions | ||
|
||
After building transactions, we need to sign them, send them to the network, and manage the nonce and gas price to ensure they are mined. This functionality is provided by: | ||
- [txmgr](./txmgr/README.md) | ||
- uses a wallet to sign and submit transactions, but then manages them by resubmitting with higher gas prices until they are mined. | ||
- [wallet](./clients/wallet) | ||
- uses a signerv2 to sign transactions, sends them to the network and can query for their receipts | ||
- wallet abstraction is needed because "wallets", such as fireblocks, both sign and send transactions to the network (they don't simply return signed bytes so that we can send them ourselves) | ||
- [signerv2](../signerv2/README.md) | ||
- signs transactions |
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,3 @@ | ||
# Wallet | ||
|
||
TODO |
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,70 @@ | ||
package wallet | ||
|
||
import ( | ||
"context" | ||
"math/big" | ||
"testing" | ||
"time" | ||
|
||
"github.com/Layr-Labs/eigensdk-go/signerv2" | ||
"github.com/Layr-Labs/eigensdk-go/testutils" | ||
"github.com/ethereum/go-ethereum/core/types" | ||
"github.com/ethereum/go-ethereum/crypto" | ||
"github.com/ethereum/go-ethereum/ethclient" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
var ( | ||
chainId = big.NewInt(31337) | ||
) | ||
|
||
func TestPrivateKeyWallet(t *testing.T) { | ||
logger := testutils.NewTestLogger() | ||
|
||
t.Run("SendTransaction + GetTransactionReceipt", func(t *testing.T) { | ||
anvilC, err := testutils.StartAnvilContainer("") | ||
require.NoError(t, err) | ||
ctxWithTimeout, cancel := context.WithTimeout(context.Background(), 5*time.Second) | ||
defer cancel() | ||
anvilHttpEndpoint, err := anvilC.Endpoint(ctxWithTimeout, "http") | ||
require.NoError(t, err) | ||
ethClient, err := ethclient.Dial(anvilHttpEndpoint) | ||
require.NoError(t, err) | ||
|
||
ecdsaPrivKeyHex := "ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80" | ||
ecdsaPrivKey, err := crypto.HexToECDSA(ecdsaPrivKeyHex) | ||
require.NoError(t, err) | ||
signerV2, signerAddr, err := signerv2.SignerFromConfig(signerv2.Config{PrivateKey: ecdsaPrivKey}, chainId) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
skWallet, err := NewPrivateKeyWallet(ethClient, signerV2, signerAddr, logger) | ||
require.NoError(t, err) | ||
|
||
tx := types.NewTx(&types.DynamicFeeTx{ | ||
ChainID: chainId, | ||
Nonce: 0, | ||
GasTipCap: big.NewInt(1), | ||
GasFeeCap: big.NewInt(1_000_000_000), | ||
Gas: 21000, | ||
To: &signerAddr, | ||
Value: big.NewInt(1), | ||
}) | ||
ctxWithTimeout, cancel = context.WithTimeout(context.Background(), 5*time.Second) | ||
defer cancel() | ||
txId, err := skWallet.SendTransaction(ctxWithTimeout, tx) | ||
require.NoError(t, err) | ||
|
||
// need to give some time for anvil to process the tx and mine the block | ||
// TODO: shall we expose a public WaitForTxReceipt function in the wallet interface, or somewhere else? | ||
time.Sleep(3 * time.Second) | ||
|
||
ctxWithTimeout, cancel = context.WithTimeout(context.Background(), 5*time.Second) | ||
defer cancel() | ||
receipt, err := skWallet.GetTransactionReceipt(ctxWithTimeout, txId) | ||
require.NoError(t, err) | ||
// make sure the txHash in the mined tx receipt matches the once we sent | ||
require.Equal(t, txId, receipt.TxHash.String()) | ||
}) | ||
} |
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 |
---|---|---|
@@ -1,12 +1,20 @@ | ||
## Transaction Manager | ||
|
||
Transaction Manager is responsible for | ||
* Building transactions | ||
* Estimating fees and adding buffer | ||
* Estimating fees and adding gas limit buffer | ||
* Signing transactions | ||
* Sending transactions to the network | ||
* Doing transaction nonce and gas price management to ensure transactions are mined | ||
|
||
|
||
### Simple Transaction Manager | ||
Here's the flow of the simple transaction manager which is used to send smart contract | ||
transactions to the network. | ||
Here's the flow of the simple transaction manager which is used to send smart contract transactions to the network. | ||
![Simple Transaction Manager](./simple-tx-manager-flow.png) | ||
|
||
### Simple Transaction Manager | ||
|
||
The simple txmgr simply sends transactions to the network, waits for them to be mined, and returns the receipt. It doesn't do any managing. | ||
|
||
### Geometric Transaction Manager | ||
|
||
The geometric txmgr is a more advanced version of the simple txmgr. It sends transactions to the network, waits for them to be mined, and if they are not mined within a certain time, it bumps the gas price geometrically and resubmits the transaction. This process is repeated until the transaction is mined. |
Oops, something went wrong.