Skip to content

Commit

Permalink
we were printing tx hash of half-built transactions, which was pointl…
Browse files Browse the repository at this point in the history
…ess (#114)

better tx hash log msg

removed double logging

remove main.go that was committed by mistake

made WrapError public so we can reuse it in the codebase

print txhash of failed txs for easier debugging

removed redundant if statement
  • Loading branch information
samlaf authored Feb 14, 2024
1 parent b72af28 commit e6e6a81
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 26 deletions.
15 changes: 6 additions & 9 deletions chainio/clients/avsregistry/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/Layr-Labs/eigensdk-go/crypto/bls"
"github.com/Layr-Labs/eigensdk-go/logging"
"github.com/Layr-Labs/eigensdk-go/types"
sdkutils "github.com/Layr-Labs/eigensdk-go/utils"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
gethcommon "github.com/ethereum/go-ethereum/common"
gethtypes "github.com/ethereum/go-ethereum/core/types"
Expand Down Expand Up @@ -255,8 +256,7 @@ func (w *AvsRegistryChainWriter) RegisterOperatorInQuorumWithAVSRegistryCoordina
if err != nil {
return nil, errors.New("failed to send tx with err: " + err.Error())
}
w.logger.Infof("tx hash: %s", tx.Hash().String())
w.logger.Info("registered operator with the AVS's registry coordinator")
w.logger.Info("succesfully registered operator with AVS registry coordinator", "tx hash", receipt.TxHash.String())
return receipt, nil
}

Expand All @@ -265,7 +265,7 @@ func (w *AvsRegistryChainWriter) UpdateStakesOfEntireOperatorSetForQuorums(
operatorsPerQuorum [][]gethcommon.Address,
quorumNumbers []byte,
) (*gethtypes.Receipt, error) {
w.logger.Info("updating stakes for entire operator set", "quorumNumbers", quorumNumbers)
w.logger.Info("updating stakes for entire operator set", "quorumNumbers", sdkutils.ConvertQuorumsBytesToInts(quorumNumbers))
noSendTxOpts, err := w.txMgr.GetNoSendTxOpts()
if err != nil {
return nil, err
Expand All @@ -278,8 +278,7 @@ func (w *AvsRegistryChainWriter) UpdateStakesOfEntireOperatorSetForQuorums(
if err != nil {
return nil, errors.New("failed to send tx with err: " + err.Error())
}
w.logger.Infof("tx hash: %s", tx.Hash().String())
w.logger.Info("updated stakes for entire operator set", "quorumNumbers", quorumNumbers)
w.logger.Info("succesfully updated stakes for entire operator set", "tx hash", receipt.TxHash.String(), "quorumNumbers", sdkutils.ConvertQuorumsBytesToInts(quorumNumbers))
return receipt, nil

}
Expand All @@ -301,8 +300,7 @@ func (w *AvsRegistryChainWriter) UpdateStakesOfOperatorSubsetForAllQuorums(
if err != nil {
return nil, errors.New("failed to send tx with err: " + err.Error())
}
w.logger.Infof("tx hash: %s", tx.Hash().String())
w.logger.Info("updated stakes of operator subset for all quorums", "operators", operators)
w.logger.Info("succesfully updated stakes of operator subset for all quorums", "tx hash", receipt.TxHash.String(), "operators", operators)
return receipt, nil

}
Expand All @@ -325,7 +323,6 @@ func (w *AvsRegistryChainWriter) DeregisterOperator(
if err != nil {
return nil, errors.New("failed to send tx with err: " + err.Error())
}
w.logger.Infof("tx hash: %s", tx.Hash().String())
w.logger.Info("deregistered operator with the AVS's registry coordinator")
w.logger.Info("succesfully deregistered operator with the AVS's registry coordinator", "tx hash", receipt.TxHash.String())
return receipt, nil
}
13 changes: 5 additions & 8 deletions chainio/clients/elcontracts/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func (w *ELChainWriter) RegisterAsOperator(ctx context.Context, operator types.O
if err != nil {
return nil, errors.New("failed to send tx with err: " + err.Error())
}
w.logger.Infof("tx hash: %s", tx.Hash().String())
w.logger.Info("tx succesfully included", "tx hash", receipt.TxHash.String())

return receipt, nil
}
Expand All @@ -156,24 +156,21 @@ func (w *ELChainWriter) UpdateOperatorDetails(
if err != nil {
return nil, err
}
_, err = w.txMgr.Send(ctx, tx)
receipt, err := w.txMgr.Send(ctx, tx)
if err != nil {
return nil, errors.New("failed to send tx with err: " + err.Error())
}
w.logger.Infof("tx hash: %s", tx.Hash().String())
w.logger.Infof("updated operator metadata URI for operator %s to EigenLayer", operator.Address)
w.logger.Info("succesfully updated operator metadata URI", "tx hash", receipt.TxHash.String(), "operator", operator.Address)

tx, err = w.delegationManager.UpdateOperatorMetadataURI(noSendTxOpts, operator.MetadataUrl)
if err != nil {
return nil, err
}
receipt, err := w.txMgr.Send(ctx, tx)
receipt, err = w.txMgr.Send(ctx, tx)
if err != nil {
return nil, errors.New("failed to send tx with err: " + err.Error())
}
w.logger.Infof("tx hash: %s", tx.Hash().String())

w.logger.Infof("updated operator details of operator %s to EigenLayer", operator.Address)
w.logger.Info("succesfully updated operator details", "tx hash", receipt.TxHash.String(), "operator", operator.Address)
return receipt, nil
}

Expand Down
14 changes: 7 additions & 7 deletions chainio/txmgr/txmgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/Layr-Labs/eigensdk-go/logging"
"github.com/Layr-Labs/eigensdk-go/signerv2"
sdktypes "github.com/Layr-Labs/eigensdk-go/types"
"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
Expand Down Expand Up @@ -82,19 +83,21 @@ func NewSimpleTxManager(
func (m *SimpleTxManager) Send(ctx context.Context, tx *types.Transaction) (*types.Receipt, error) {

// Estimate gas and nonce
m.log.Debug("Estimating gas and nonce", "tx", tx.Hash().Hex())
// can't print tx hash in logs because the tx changes below when we complete and sign it
// so the txHash is meaningless at this point
m.log.Debug("Estimating gas and nonce")
tx, err := m.estimateGasAndNonce(ctx, tx)
if err != nil {
return nil, err
}

m.log.Debug("Getting signer for tx", "tx", tx.Hash().Hex())
m.log.Debug("Getting signer for tx")
signer, err := m.signerFn(ctx, m.sender)
if err != nil {
return nil, err
}

m.log.Debug("Sending transaction", "tx", tx.Hash().Hex())
m.log.Debug("Sending transaction")
opts := &bind.TransactOpts{
From: m.sender,
Nonce: new(big.Int).SetUint64(tx.Nonce()),
Expand All @@ -117,10 +120,7 @@ func (m *SimpleTxManager) Send(ctx context.Context, tx *types.Transaction) (*typ

tx, err = contract.RawTransact(opts, tx.Data())
if err != nil {
return nil, fmt.Errorf("send: failed to send txn: %w", err)
}
if err != nil {
return nil, err
return nil, sdktypes.WrapError(fmt.Errorf("send: tx %v failed.", tx.Hash().String()), err)
}

receipt := m.waitForTx(ctx, tx)
Expand Down
4 changes: 2 additions & 2 deletions signer/basic_signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (

sdkethclient "github.com/Layr-Labs/eigensdk-go/chainio/clients/eth"
"github.com/Layr-Labs/eigensdk-go/logging"
"github.com/Layr-Labs/eigensdk-go/utils"
"github.com/Layr-Labs/eigensdk-go/types"
"github.com/Layr-Labs/eigensdk-go/utils"

"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/accounts/abi"
Expand Down Expand Up @@ -165,7 +165,7 @@ func (s *BasicSigner) EnsureTransactionEvaled(tx *gethtypes.Transaction, tag str
return nil, fmt.Errorf("Transaction failed (tag: %v, txHash: %v, status: %v, gasUsed: %v)", tag, tx.Hash().Hex(), receipt.Status, receipt.GasUsed)
}
s.logger.Debug("successfully submitted transaction",
"txHash", tx.Hash().Hex(),
"txHash", receipt.TxHash.Hex(),
"tag", tag,
"gasUsed", receipt.GasUsed,
)
Expand Down
8 changes: 8 additions & 0 deletions utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,11 @@ func IsValidEthereumAddress(address string) bool {
re := regexp.MustCompile("^0x[0-9a-fA-F]{40}$")
return re.MatchString(address)
}

func ConvertQuorumsBytesToInts(quorums []byte) []int {
var quorumsInts []int
for _, quorum := range quorums {
quorumsInts = append(quorumsInts, int(quorum))
}
return quorumsInts
}

0 comments on commit e6e6a81

Please sign in to comment.