forked from OffchainLabs/nitro
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from EspressoSystems/hotshot-client
Implement HotShot commitment reader
- Loading branch information
Showing
15 changed files
with
227 additions
and
35 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package arbnode | ||
|
||
import ( | ||
"fmt" | ||
"math/big" | ||
|
||
"github.com/ethereum/go-ethereum/accounts/abi/bind" | ||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/offchainlabs/nitro/arbos/espresso" | ||
"github.com/offchainlabs/nitro/arbos/espresso/hotshot" | ||
) | ||
|
||
type HotShotReader struct { | ||
HotShot hotshot.Hotshot | ||
} | ||
|
||
func NewHotShotReader(hotShotAddr common.Address, l1client bind.ContractBackend) (*HotShotReader, error) { | ||
hotshot, err := hotshot.NewHotshot(hotShotAddr, l1client) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &HotShotReader{ | ||
HotShot: *hotshot, | ||
}, nil | ||
} | ||
|
||
// L1HotShotCommitmentFromHeight returns a HotShot commitments to a sequencer block | ||
// This is used in the derivation pipeline to validate sequencer batches in Espresso mode | ||
func (h *HotShotReader) L1HotShotCommitmentFromHeight(blockHeight uint64) (*espresso.Commitment, error) { | ||
var comm espresso.Commitment | ||
// Check if the requested commitments are even available yet on L1. | ||
contractBlockHeight, err := h.HotShot.HotshotCaller.BlockHeight(nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
if contractBlockHeight.Cmp(big.NewInt(int64(blockHeight))) < 0 { | ||
return nil, fmt.Errorf("commitment at block height %d is unavailable (current contract block height %d)", blockHeight, contractBlockHeight) | ||
} | ||
|
||
commAsInt, err := h.HotShot.HotshotCaller.Commitments(nil, big.NewInt(int64(blockHeight))) | ||
if err != nil { | ||
return nil, err | ||
} | ||
if commAsInt.Cmp(big.NewInt(0)) == 0 { | ||
// A commitment of 0 indicates that this commitment hasn't been set yet in the contract. | ||
// Since we checked the contract block height above, this can only happen if there was | ||
// a reorg on L1 just now. In this case, return an error rather than reporting | ||
// definitive commitments. The caller will retry and we will succeed eventually when we | ||
// manage to get a consistent snapshot of the L1. | ||
// | ||
// Note that in all other reorg cases, where the L1 reorgs but we read a nonzero | ||
// commitment, we are fine, since the HotShot contract will only ever record a single | ||
// ledger, consistent across all L1 forks, determined by HotShot consensus. The only | ||
// question is whether the recorded ledger extends far enough for the commitments we're | ||
// trying to read on the current fork of L1. | ||
return nil, fmt.Errorf("read 0 for commitment %d at block height %d, this indicates an L1 reorg", blockHeight, contractBlockHeight) | ||
} | ||
comm, err = espresso.CommitmentFromUint256(espresso.NewU256().SetBigInt(commAsInt)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &comm, nil | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"persistent": { | ||
"chain": "local" | ||
}, | ||
"ws": { | ||
"addr": "" | ||
}, | ||
"http": { | ||
"addr": "" | ||
}, | ||
"validation": { | ||
"api-auth": true, | ||
"api-public": false | ||
}, | ||
"auth": { | ||
"jwtsecret": "./config/val_jwt.hex", | ||
"addr": "0.0.0.0" | ||
} | ||
} |
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,80 @@ | ||
{ | ||
"parent-chain": { | ||
"connection": { | ||
"url": "ws://localhost:8546" | ||
}, | ||
"wallet": { | ||
"account": "0xE46fC174A70D204A737689996F6dA33Ed14e1457", | ||
"password": "passphrase", | ||
"pathname": "/Users/ngolub/.arbitrum/local/keystore" | ||
} | ||
}, | ||
"chain": { | ||
"id": 412346, | ||
"info-files": [ | ||
"./config/l2_chain_info.json" | ||
] | ||
}, | ||
"execution": { | ||
"sequencer": { | ||
"enable": false | ||
} | ||
}, | ||
"node": { | ||
"staker": { | ||
"dangerous": { | ||
"without-block-validator": false | ||
}, | ||
"disable-challenge": false, | ||
"enable": true, | ||
"staker-interval": "10s", | ||
"make-assertion-interval": "10s", | ||
"strategy": "MakeNodes", | ||
"use-smart-contract-wallet": true | ||
}, | ||
"sequencer": false, | ||
"delayed-sequencer": { | ||
"enable": false | ||
}, | ||
"seq-coordinator": { | ||
"enable": false, | ||
"redis-url": "redis://localhost:6379", | ||
"lockout-duration": "30s", | ||
"lockout-spare": "1s", | ||
"my-url": "", | ||
"retry-interval": "0.5s", | ||
"seq-num-duration": "24h0m0s", | ||
"update-interval": "3s" | ||
}, | ||
"batch-poster": { | ||
"enable": false, | ||
"redis-url": "redis://localhost:6379", | ||
"max-delay": "30s", | ||
"data-poster": { | ||
"redis-signer": { | ||
"signing-key": "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" | ||
}, | ||
"wait-for-l1-finality": false | ||
} | ||
}, | ||
"block-validator": { | ||
"validation-server": { | ||
"url": "ws://localhost:8949", | ||
"jwtsecret": "./config/val_jwt.hex" | ||
}, | ||
"hotshot-address": "0x217788c286797d56cd59af5e493f3699c39cbbe8", | ||
"espresso": true | ||
} | ||
}, | ||
"persistent": { | ||
"chain": "local" | ||
}, | ||
"ws": { | ||
"addr": "0.0.0.0" | ||
}, | ||
"http": { | ||
"addr": "0.0.0.0", | ||
"vhosts": "*", | ||
"corsdomain": "*" | ||
} | ||
} |
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
Oops, something went wrong.