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

Upgrade eigensdk-go and go-ethereum #323

Merged
merged 3 commits into from
Mar 8, 2024
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
6 changes: 3 additions & 3 deletions clients/retrieval_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (
"errors"
"fmt"

"github.com/Layr-Labs/eigenda/common"
"github.com/Layr-Labs/eigenda/core"
"github.com/Layr-Labs/eigenda/encoding"
"github.com/Layr-Labs/eigensdk-go/logging"

"github.com/gammazero/workerpool"
"github.com/wealdtech/go-merkletree"
Expand All @@ -25,7 +25,7 @@ type RetrievalClient interface {
}

type retrievalClient struct {
logger common.Logger
logger logging.Logger
indexedChainState core.IndexedChainState
assignmentCoordinator core.AssignmentCoordinator
nodeClient NodeClient
Expand All @@ -36,7 +36,7 @@ type retrievalClient struct {
var _ RetrievalClient = (*retrievalClient)(nil)

func NewRetrievalClient(
logger common.Logger,
logger logging.Logger,
chainState core.IndexedChainState,
assignmentCoordinator core.AssignmentCoordinator,
nodeClient NodeClient,
Expand Down
8 changes: 2 additions & 6 deletions clients/tests/retrieval_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (

"github.com/Layr-Labs/eigenda/clients"
clientsmock "github.com/Layr-Labs/eigenda/clients/mock"
"github.com/Layr-Labs/eigenda/common/logging"
"github.com/Layr-Labs/eigenda/core"
coreindexer "github.com/Layr-Labs/eigenda/core/indexer"
coremock "github.com/Layr-Labs/eigenda/core/mock"
Expand All @@ -17,6 +16,7 @@ import (
"github.com/Layr-Labs/eigenda/encoding/kzg/prover"
"github.com/Layr-Labs/eigenda/encoding/kzg/verifier"
indexermock "github.com/Layr-Labs/eigenda/indexer/mock"
"github.com/Layr-Labs/eigensdk-go/logging"
"github.com/consensys/gnark-crypto/ecc/bn254"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
Expand Down Expand Up @@ -86,11 +86,7 @@ func setup(t *testing.T) {
if err != nil {
t.Fatal(err)
}
logger, err := logging.GetLogger(logging.DefaultCLIConfig())
if err != nil {
panic("failed to create a new logger")
}

logger := logging.NewNoopLogger()
indexer = &indexermock.MockIndexer{}
indexer.On("Index").Return(nil).Once()

Expand Down
6 changes: 3 additions & 3 deletions common/aws/dynamodb/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"math"
"sync"

"github.com/Layr-Labs/eigenda/common"
commonaws "github.com/Layr-Labs/eigenda/common/aws"
"github.com/Layr-Labs/eigensdk-go/logging"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/credentials"
Expand Down Expand Up @@ -44,10 +44,10 @@ type QueryResult struct {

type Client struct {
dynamoClient *dynamodb.Client
logger common.Logger
logger logging.Logger
}

func NewClient(cfg commonaws.ClientConfig, logger common.Logger) (*Client, error) {
func NewClient(cfg commonaws.ClientConfig, logger logging.Logger) (*Client, error) {
var err error
once.Do(func() {
createClient := func(service, region string, options ...interface{}) (aws.Endpoint, error) {
Expand Down
11 changes: 5 additions & 6 deletions common/aws/dynamodb/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ import (
"testing"
"time"

"github.com/Layr-Labs/eigenda/common"
commonaws "github.com/Layr-Labs/eigenda/common/aws"
commondynamodb "github.com/Layr-Labs/eigenda/common/aws/dynamodb"
test_utils "github.com/Layr-Labs/eigenda/common/aws/dynamodb/utils"
"github.com/Layr-Labs/eigenda/common/logging"
"github.com/Layr-Labs/eigenda/inabox/deploy"
"github.com/Layr-Labs/eigensdk-go/logging"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/dynamodb"
"github.com/aws/aws-sdk-go-v2/service/dynamodb/types"
Expand Down Expand Up @@ -53,18 +54,16 @@ func setup(m *testing.M) {
}
}

logger, err := logging.GetLogger(logging.DefaultCLIConfig())
if err != nil {
teardown()
panic("failed to get logger")
}
loggerConfig := common.DefaultLoggerConfig()
logger := logging.NewSlogJsonLogger(loggerConfig.OutputWriter, &loggerConfig.HandlerOpts)

clientConfig = commonaws.ClientConfig{
Region: "us-east-1",
AccessKey: "localstack",
SecretAccessKey: "localstack",
EndpointURL: fmt.Sprintf("http://0.0.0.0:%s", localStackPort),
}
var err error
dynamoClient, err = commondynamodb.NewClient(clientConfig, logger)
if err != nil {
teardown()
Expand Down
6 changes: 3 additions & 3 deletions common/aws/s3/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"errors"
"sync"

"github.com/Layr-Labs/eigenda/common"
commonaws "github.com/Layr-Labs/eigenda/common/aws"
"github.com/Layr-Labs/eigensdk-go/logging"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/credentials"
Expand All @@ -28,12 +28,12 @@ type Object struct {

type client struct {
s3Client *s3.Client
logger common.Logger
logger logging.Logger
}

var _ Client = (*client)(nil)

func NewClient(ctx context.Context, cfg commonaws.ClientConfig, logger common.Logger) (*client, error) {
func NewClient(ctx context.Context, cfg commonaws.ClientConfig, logger logging.Logger) (*client, error) {
var err error
once.Do(func() {
customResolver := aws.EndpointResolverWithOptionsFunc(func(service, region string, options ...interface{}) (aws.Endpoint, error) {
Expand Down
17 changes: 9 additions & 8 deletions common/geth/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"time"

"github.com/Layr-Labs/eigenda/common"
"github.com/Layr-Labs/eigensdk-go/logging"
"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
Expand All @@ -31,13 +32,13 @@ type EthClient struct {
chainID *big.Int
AccountAddress gethcommon.Address
Contracts map[gethcommon.Address]*bind.BoundContract
Logger common.Logger
Logger logging.Logger
numConfirmations int
}

var _ common.EthClient = (*EthClient)(nil)

func NewClient(config EthClientConfig, logger common.Logger) (*EthClient, error) {
func NewClient(config EthClientConfig, logger logging.Logger) (*EthClient, error) {
chainClient, err := ethclient.Dial(config.RPCURL)
if err != nil {
return nil, fmt.Errorf("NewClient: cannot connect to provider: %w", err)
Expand Down Expand Up @@ -210,7 +211,7 @@ func (c *EthClient) EnsureTransactionEvaled(ctx context.Context, tx *types.Trans
c.Logger.Error("Transaction Failed", "tag", tag, "txHash", tx.Hash().Hex(), "status", receipt.Status, "GasUsed", receipt.GasUsed)
return nil, ErrTransactionFailed
}
c.Logger.Trace("transaction confirmed", "txHash", tx.Hash().Hex(), "tag", tag, "gasUsed", receipt.GasUsed)
c.Logger.Debug("transaction confirmed", "txHash", tx.Hash().Hex(), "tag", tag, "gasUsed", receipt.GasUsed)
return receipt, nil
}

Expand All @@ -225,7 +226,7 @@ func (c *EthClient) EnsureAnyTransactionEvaled(ctx context.Context, txs []*types
c.Logger.Error("Transaction Failed", "tag", tag, "txHash", receipt.TxHash.Hex(), "status", receipt.Status, "GasUsed", receipt.GasUsed)
return nil, ErrTransactionFailed
}
c.Logger.Trace("transaction confirmed", "txHash", receipt.TxHash.Hex(), "tag", tag, "gasUsed", receipt.GasUsed)
c.Logger.Debug("transaction confirmed", "txHash", receipt.TxHash.Hex(), "tag", tag, "gasUsed", receipt.GasUsed)
return receipt, nil
}

Expand All @@ -245,20 +246,20 @@ func (c *EthClient) waitMined(ctx context.Context, txs []*types.Transaction) (*t
chainTip, err := c.BlockNumber(ctx)
if err == nil {
if receipt.BlockNumber.Uint64()+uint64(c.numConfirmations) > chainTip {
c.Logger.Trace("EnsureTransactionEvaled: transaction has been mined but don't have enough confirmations at current chain tip", "txnBlockNumber", receipt.BlockNumber.Uint64(), "numConfirmations", c.numConfirmations, "chainTip", chainTip)
c.Logger.Debug("EnsureTransactionEvaled: transaction has been mined but don't have enough confirmations at current chain tip", "txnBlockNumber", receipt.BlockNumber.Uint64(), "numConfirmations", c.numConfirmations, "chainTip", chainTip)
break
} else {
return receipt, nil
}
} else {
c.Logger.Trace("EnsureTransactionEvaled: failed to get chain tip while waiting for transaction to mine", "err", err)
c.Logger.Debug("EnsureTransactionEvaled: failed to get chain tip while waiting for transaction to mine", "err", err)
}
}

if errors.Is(err, ethereum.NotFound) {
c.Logger.Trace("Transaction not yet mined", "txHash", tx.Hash().Hex())
c.Logger.Debug("Transaction not yet mined", "txHash", tx.Hash().Hex())
} else if err != nil {
c.Logger.Trace("Transaction receipt retrieval failed", "err", err)
c.Logger.Debug("Transaction receipt retrieval failed", "err", err)
}
}
// Wait for the next round.
Expand Down
3 changes: 2 additions & 1 deletion common/geth/instrumented_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"time"

"github.com/Layr-Labs/eigenda/common"
"github.com/Layr-Labs/eigensdk-go/logging"
rpccalls "github.com/Layr-Labs/eigensdk-go/metrics/collectors/rpc_calls"
"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/accounts/abi"
Expand All @@ -30,7 +31,7 @@ type InstrumentedEthClient struct {

var _ common.EthClient = (*InstrumentedEthClient)(nil)

func NewInstrumentedEthClient(config EthClientConfig, rpcCallsCollector *rpccalls.Collector, logger common.Logger) (*InstrumentedEthClient, error) {
func NewInstrumentedEthClient(config EthClientConfig, rpcCallsCollector *rpccalls.Collector, logger logging.Logger) (*InstrumentedEthClient, error) {
ethClient, err := NewClient(config, logger)
if err != nil {
return nil, err
Expand Down
67 changes: 67 additions & 0 deletions common/logger_config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package common

import (
"io"
"log/slog"
"os"

"github.com/urfave/cli"
)

const (
PathFlagName = "log.path"
LevelFlagName = "log.level"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using one common level for both std and file logs

)

type LoggerConfig struct {
OutputWriter io.Writer
HandlerOpts slog.HandlerOptions
}

func LoggerCLIFlags(envPrefix string, flagPrefix string) []cli.Flag {
return []cli.Flag{
cli.StringFlag{
Name: PrefixFlag(flagPrefix, LevelFlagName),
Usage: `The lowest log level that will be output. Accepted options are "debug", "info", "warn", "error"`,
Value: "info",
EnvVar: PrefixEnvVar(envPrefix, "LOG_LEVEL"),
},
cli.StringFlag{
Name: PrefixFlag(flagPrefix, PathFlagName),
Usage: "Path to file where logs will be written",
Value: "",
EnvVar: PrefixEnvVar(envPrefix, "LOG_PATH"),
},
}
}

func DefaultLoggerConfig() LoggerConfig {
return LoggerConfig{
OutputWriter: os.Stdout,
HandlerOpts: slog.HandlerOptions{
AddSource: true,
Level: slog.LevelDebug,
},
}
}

func ReadLoggerCLIConfig(ctx *cli.Context, flagPrefix string) (*LoggerConfig, error) {
cfg := DefaultLoggerConfig()
path := ctx.GlobalString(PrefixFlag(flagPrefix, PathFlagName))
if path != "" {
f, err := os.OpenFile(path, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0644)
if err != nil {
return nil, err
}
cfg.OutputWriter = io.MultiWriter(os.Stdout, f)
}
logLevel := ctx.GlobalString(PrefixFlag(flagPrefix, LevelFlagName))
var level slog.Level
err := level.UnmarshalText([]byte(logLevel))
if err != nil {
panic("failed to parse log level " + logLevel)
}
cfg.HandlerOpts.Level = level

return &cfg, nil
}
85 changes: 0 additions & 85 deletions common/logging.go

This file was deleted.

Loading
Loading