Skip to content

Commit

Permalink
allow sender to be any wallet
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrower95 committed Aug 12, 2024
1 parent 4fc932b commit 94278dc
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 19 deletions.
11 changes: 9 additions & 2 deletions cli/core/checkpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,19 @@ func SubmitCheckpointProof(ctx context.Context, owner, eigenpodAddress string, c
tracing.OnStartSection("pepe::proof::checkpoint::batch::wait", map[string]string{
"chunk": fmt.Sprintf("%d", i),
})
bind.WaitMined(ctx, eth, txn)

if !noSend {
bind.WaitMined(ctx, eth, txn)
}
tracing.OnEndSection()
color.Green("OK")
}

color.Green("Complete! re-run with `status` to see the updated Eigenpod state.")
if !noSend {
color.Green("Complete! re-run with `status` to see the updated Eigenpod state.")
} else {
color.Yellow("Submit these proofs to network and re-run with `status` to see the updated Eigenpod state.")
}
return transactions, nil
}

Expand Down
32 changes: 16 additions & 16 deletions cli/core/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
gethCommon "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/ethereum/go-ethereum/params"
Expand Down Expand Up @@ -116,40 +117,31 @@ type Owner = struct {
IsDryRun bool
}

func StartCheckpoint(ctx context.Context, eigenpodAddress string, ownerPrivateKey string, chainId *big.Int, eth *ethclient.Client, forceCheckpoint bool, noSend bool) (uint64, error) {
func StartCheckpoint(ctx context.Context, eigenpodAddress string, ownerPrivateKey string, chainId *big.Int, eth *ethclient.Client, forceCheckpoint bool, noSend bool) (*types.Transaction, error) {
ownerAccount, err := PrepareAccount(&ownerPrivateKey, chainId, noSend)
if err != nil {
return 0, fmt.Errorf("failed to parse private key: %w", err)
return nil, fmt.Errorf("failed to parse private key: %w", err)
}

eigenPod, err := onchain.NewEigenPod(gethCommon.HexToAddress(eigenpodAddress), eth)
if err != nil {
return 0, fmt.Errorf("failed to reach eigenpod: %w", err)
return nil, fmt.Errorf("failed to reach eigenpod: %w", err)
}

revertIfNoBalance := !forceCheckpoint

txn, err := eigenPod.StartCheckpoint(ownerAccount.TransactionOptions, revertIfNoBalance)
if err != nil {
if !forceCheckpoint {
return 0, fmt.Errorf("failed to start checkpoint (try running again with `--force`): %w", err)
return nil, fmt.Errorf("failed to start checkpoint (try running again with `--force`): %w", err)
}

return 0, fmt.Errorf("failed to start checkpoint: %w", err)
return nil, fmt.Errorf("failed to start checkpoint: %w", err)
}

color.Green("starting checkpoint: %s.. (waiting for txn to be mined)...", txn.Hash().Hex())

bind.WaitMined(ctx, eth, txn)
color.Green("starting checkpoint: %s..", txn.Hash().Hex())

color.Green("started checkpoint! txn: %s", txn.Hash().Hex())

currentCheckpoint, err := GetCurrentCheckpoint(eigenpodAddress, eth)
if err != nil {
return 0, fmt.Errorf("failed to fetch current checkpoint: %w", err)
}

return currentCheckpoint, nil
return txn, nil
}

func GetBeaconClient(beaconUri string) (BeaconClient, error) {
Expand Down Expand Up @@ -351,6 +343,14 @@ func PrepareAccount(owner *string, chainID *big.Int, noSend bool) (*Owner, error
}

auth.NoSend = noSend
if noSend {
// we don't want any estimation to happen by accident (since it implies simulation of the txn),
// so specify values for gas and all of that.
auth.GasPrice = nil // big.NewInt(10) // Gas price to use for the transaction execution (nil = gas price oracle)
auth.GasFeeCap = big.NewInt(10) // big.NewInt(10) // Gas fee cap to use for the 1559 transaction execution (nil = gas price oracle)
auth.GasTipCap = big.NewInt(2) // big.NewInt(2) // Gas priority fee cap to use for the 1559 transaction execution (nil = gas price oracle)
auth.GasLimit = 21000
}

return &Owner{
FromAddress: fromAddress,
Expand Down
32 changes: 31 additions & 1 deletion cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (

"github.com/Layr-Labs/eigenpod-proofs-generation/cli/core"
"github.com/Layr-Labs/eigenpod-proofs-generation/cli/core/onchain"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
gethCommon "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/fatih/color"
Expand Down Expand Up @@ -410,6 +412,11 @@ func main() {
out = &outProp
}

if simulateTransaction && len(sender) == 0 {
core.Panic("if using --print-calldata, please specify a --sender. Note that the transaction will not be broadcast.")
return nil
}

eth, beaconClient, chainId, err := core.GetClients(ctx, node, beacon)
core.PanicOnError("failed to reach ethereum clients", err)

Expand All @@ -434,14 +441,32 @@ func main() {
currentCheckpoint, err := core.GetCurrentCheckpoint(eigenpodAddress, eth)
core.PanicOnError("failed to load checkpoint", err)

eigenpod, err := onchain.NewEigenPod(common.HexToAddress(eigenpodAddress), eth)
core.PanicOnError("failed to connect to eigenpod", err)

if currentCheckpoint == 0 {
if len(sender) != 0 {
if !noPrompt && !simulateTransaction {
core.PanicIfNoConsent(core.StartCheckpointProofConsent())
}

newCheckpoint, err := core.StartCheckpoint(ctx, eigenpodAddress, sender, chainId, eth, forceCheckpoint, simulateTransaction)
txn, err := core.StartCheckpoint(ctx, eigenpodAddress, sender, chainId, eth, forceCheckpoint, simulateTransaction)
core.PanicOnError("failed to start checkpoint", err)

if !simulateTransaction {
color.Green("(waiting for txn to be mined)...")
bind.WaitMined(ctx, eth, txn)
color.Green("started checkpoint! txn: %s", txn.Hash().Hex())
} else {
fmt.Printf("This transaction will start a checkpoint. Please submit and re-run to generate your proofs. (NOTE: If you generated this with --force, this may revert on the network.)\n")
fmt.Printf("\ttransaction.to: %s\n", txn.To().Hex())
fmt.Printf("\ttransaction.calldata: %s\n", common.Bytes2Hex(txn.Data()))
return nil
}

newCheckpoint, err := eigenpod.CurrentCheckpointTimestamp(nil)
core.PanicOnError("failed to fetch current checkpoint", err)

currentCheckpoint = newCheckpoint
} else {
core.PanicOnError("no checkpoint active and no private key provided to start one", errors.New("no checkpoint"))
Expand Down Expand Up @@ -508,6 +533,11 @@ func main() {
eth, beaconClient, chainId, err := core.GetClients(ctx, node, beacon)
core.PanicOnError("failed to reach ethereum clients", err)

if simulateTransaction && len(sender) == 0 {
core.Panic("if using --print-calldata, please specify a --sender. Note that the transaction will not be broadcast.")
return nil
}

var specificValidatorIndex *big.Int = nil
if specificValidator != math.MaxUint64 && specificValidator != 0 {
specificValidatorIndex = new(big.Int).SetUint64(specificValidator)
Expand Down

0 comments on commit 94278dc

Please sign in to comment.