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

Add BOLD System Test That Successfully Completes a Challenge #1902

Merged
merged 74 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from 67 commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
1564648
update execution_run to support Generalized History Provider
amsanghi Aug 17, 2023
f696079
Align with latest bold interface
amsanghi Aug 21, 2023
6f542af
Minor fix
amsanghi Aug 21, 2023
04241b0
Minor fix
amsanghi Aug 21, 2023
0f8bf4d
fix computeStepIncrement
amsanghi Aug 21, 2023
2e0bc77
minor fix
amsanghi Aug 21, 2023
1110abd
Merge branch 'bold' into generalize_history
amsanghi Aug 21, 2023
0a60c12
update based on latest changes in https://github.com/OffchainLabs/bol…
amsanghi Aug 23, 2023
1cd9819
add CollectProof
amsanghi Sep 12, 2023
20b6f36
Merge branch 'bold' into generalize_history
amsanghi Sep 19, 2023
46c81d2
update based on pr 440 of bold
amsanghi Sep 19, 2023
7092ecd
update commit
rauljordan Sep 21, 2023
dfee9b7
update bold commit
rauljordan Sep 25, 2023
48a3dc8
protocol system test revisit
rauljordan Sep 25, 2023
dc8f7dc
add in the sys test
rauljordan Sep 25, 2023
7ad381e
working on integration
rauljordan Sep 25, 2023
25637ff
posting assertions
rauljordan Sep 25, 2023
4b67918
posting scanning interval fixes
rauljordan Sep 25, 2023
7e52efb
fix regen
rauljordan Sep 25, 2023
9461455
debugging
rauljordan Sep 25, 2023
4e2ea7c
regen
rauljordan Sep 25, 2023
d5df068
update sub
rauljordan Sep 25, 2023
d1d4565
working up to subchallenges
rauljordan Sep 25, 2023
49321d2
update sub
rauljordan Sep 25, 2023
f539d0b
fixes
rauljordan Sep 27, 2023
377d6a6
fixing up interface for gathering leaves
rauljordan Sep 27, 2023
e185304
submod
rauljordan Sep 27, 2023
3fe8483
update dep
rauljordan Sep 27, 2023
64dbcb1
reach osp
rauljordan Sep 28, 2023
ab4c5bd
osp success
rauljordan Sep 28, 2023
a89fb18
update bold
rauljordan Oct 2, 2023
76463c5
still reaches osp
rauljordan Oct 3, 2023
f4a782f
update ref
rauljordan Oct 3, 2023
4dbb1e8
update main
rauljordan Oct 4, 2023
3dff3ca
cache tests
rauljordan Oct 4, 2023
8620dad
comments, todos
rauljordan Oct 4, 2023
91abb0e
builds
rauljordan Oct 4, 2023
5c7e04c
update commit
rauljordan Oct 4, 2023
32cf9fb
bold commit
rauljordan Oct 4, 2023
5fc5b5f
update bold ref
rauljordan Oct 5, 2023
251d2f9
tweak challenge period and ancestor blocks
rauljordan Oct 5, 2023
9ae6b43
fix delay
rauljordan Oct 5, 2023
1190c0d
revamp
rauljordan Oct 5, 2023
0e0ce25
amend provider
rauljordan Oct 5, 2023
6893eb2
update bold ref
rauljordan Oct 6, 2023
584f1ca
bold ref
rauljordan Oct 6, 2023
2b8bad6
amend bold and post batches
rauljordan Oct 6, 2023
80caa0f
attempts
rauljordan Oct 9, 2023
042ed07
include msg checks
rauljordan Oct 9, 2023
484ff98
include unit test passing execution global state range checks
rauljordan Oct 10, 2023
7fd8b7c
added coverage and simplified the state provider logic
rauljordan Oct 10, 2023
036953b
back to posting block chal edges
rauljordan Oct 10, 2023
72ef594
bisections working
rauljordan Oct 10, 2023
a22bd73
getting there
rauljordan Oct 10, 2023
33c1bf0
challenge working again
rauljordan Oct 11, 2023
c59b84e
update bold commit
rauljordan Oct 11, 2023
f35f401
update bold commit
rauljordan Oct 11, 2023
927dba2
log await confirmation of assertion
rauljordan Oct 11, 2023
952066c
add expectation
rauljordan Oct 11, 2023
434c64d
sync bold
rauljordan Oct 11, 2023
34a587d
execution fixes
rauljordan Oct 12, 2023
9e98383
update bold
rauljordan Oct 12, 2023
ba5195c
update bold
rauljordan Oct 12, 2023
44e3b17
lint
rauljordan Oct 12, 2023
1e97c64
up
rauljordan Oct 12, 2023
13b9ba0
clean
rauljordan Oct 12, 2023
51ee105
edit
rauljordan Oct 12, 2023
9372f71
patch test
rauljordan Oct 12, 2023
d8e27d1
buidls
rauljordan Oct 12, 2023
a3ebe4d
cleanup
rauljordan Oct 12, 2023
9d8ff55
sys test
rauljordan Oct 12, 2023
93cfe2e
patch up
rauljordan Oct 12, 2023
1ab39f0
build tag
rauljordan Oct 12, 2023
726983e
update bold commit
rauljordan Oct 12, 2023
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
2 changes: 1 addition & 1 deletion bold
Submodule bold updated 50 files
+1 −1 assertions/BUILD.bazel
+27 −37 assertions/poster.go
+123 −24 assertions/poster_test.go
+73 −26 assertions/scanner.go
+5 −5 assertions/scanner_test.go
+10 −0 chain-abstraction/interfaces.go
+1 −0 chain-abstraction/sol-implementation/BUILD.bazel
+12 −0 chain-abstraction/sol-implementation/assertion_chain.go
+4 −2 chain-abstraction/sol-implementation/assertion_chain_test.go
+31 −1 chain-abstraction/sol-implementation/edge_challenge_manager.go
+64 −23 chain-abstraction/sol-implementation/edge_challenge_manager_test.go
+3 −0 challenge-manager/BUILD.bazel
+19 −2 challenge-manager/chain-watcher/watcher.go
+4 −2 challenge-manager/chain-watcher/watcher_test.go
+1 −0 challenge-manager/challenge-tree/BUILD.bazel
+4 −2 challenge-manager/challenge-tree/ancestors_test.go
+2 −4 challenge-manager/challenge-tree/local_timer.go
+4 −0 challenge-manager/challenge-tree/mock/edge.go
+58 −21 challenge-manager/challenge-tree/tree.go
+37 −15 challenge-manager/challenge-tree/tree_test.go
+24 −23 challenge-manager/challenges.go
+122 −99 challenge-manager/edge-tracker/tracker.go
+72 −66 challenge-manager/manager.go
+80 −28 challenge-manager/manager_test.go
+1 −0 containers/threadsafe/BUILD.bazel
+14 −1 containers/threadsafe/slice.go
+1 −1 contracts/package.json
+1 −1 contracts/scripts/boldUpgradeFunctions.ts
+2 −2 contracts/scripts/files/localConfig.json
+1 −1 contracts/scripts/files/localNetwork.json
+14 −5 contracts/src/challengeV2/EdgeChallengeManager.sol
+2 −0 contracts/src/challengeV2/libraries/ChallengeErrors.sol
+12 −29 contracts/src/challengeV2/libraries/EdgeChallengeManagerLib.sol
+209 −66 contracts/test/challengeV2/ChallengeEdgeLib.t.sol
+211 −1 contracts/test/challengeV2/EdgeChallengeManager.t.sol
+790 −243 contracts/test/challengeV2/EdgeChallengeManagerLib.t.sol
+21 −8 layer2-state-provider/history_commitment_provider.go
+9 −5 layer2-state-provider/provider.go
+2 −2 solgen/go/assertionStakingPoolgen/assertionStakingPoolgen.go
+1 −1 solgen/go/bridgegen/bridgegen.go
+65 −3 solgen/go/challengeV2gen/challengeV2gen.go
+2 −2 solgen/go/mocksgen/mocksgen.go
+9 −9 solgen/go/rollupgen/rollupgen.go
+18 −9 state-commitments/prefix-proofs/prefix_proofs_test.go
+1 −2 testing/endtoend/basic_local_test.go
+22 −5 testing/mocks/mocks.go
+4 −2 testing/mocks/state-provider/history_provider.go
+12 −6 testing/mocks/state-provider/history_provider_test.go
+15 −15 testing/mocks/state-provider/layer2_state_provider.go
+2 −2 testing/setup/rollup_stack.go
6 changes: 5 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ require (
github.com/openzipkin/zipkin-go v0.4.0 // indirect
github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/polydawn/refmt v0.89.0 // indirect
github.com/prometheus/client_golang v1.14.0 // indirect
github.com/prometheus/client_model v0.3.0 // indirect
Expand All @@ -240,6 +241,8 @@ require (
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/samber/lo v1.36.0 // indirect
github.com/spaolacci/murmur3 v1.1.0 // indirect
github.com/stretchr/objx v0.5.0 // indirect
github.com/stretchr/testify v1.8.4 // indirect
github.com/urfave/cli/v2 v2.17.2-0.20221006022127-8f469abc00aa // indirect
github.com/vmihailenco/msgpack/v5 v5.3.5 // indirect
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
Expand Down Expand Up @@ -276,6 +279,7 @@ require (
google.golang.org/grpc v1.53.0 // indirect
google.golang.org/protobuf v1.30.0 // indirect
gopkg.in/square/go-jose.v2 v2.5.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
lukechampine.com/blake3 v1.1.7 // indirect
nhooyr.io/websocket v1.8.7 // indirect
)
Expand All @@ -302,7 +306,7 @@ require (
github.com/google/uuid v1.3.0 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/hashicorp/go-bexpr v0.1.10 // indirect
github.com/hashicorp/golang-lru v0.5.5-0.20210104140557-80c98217689d // indirect
github.com/hashicorp/golang-lru v1.0.2 // indirect
github.com/holiman/bloomfilter/v2 v2.0.3 // indirect
github.com/holiman/uint256 v1.2.2
github.com/huin/goupnp v1.1.0 // indirect
Expand Down
15 changes: 13 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ github.com/cockroachdb/pebble v0.0.0-20230209160836-829675f94811 h1:ytcWPaNPhNoG
github.com/cockroachdb/pebble v0.0.0-20230209160836-829675f94811/go.mod h1:Nb5lgvnQ2+oGlE/EyZy4+2/CxRh9KfvCXnag1vtpxVM=
github.com/cockroachdb/redact v1.1.3 h1:AKZds10rFSIj7qADf0g46UixK8NNLwWTNdCIGS5wfSQ=
github.com/cockroachdb/redact v1.1.3/go.mod h1:BVNblN9mBWFyMyqK1k3AAiSxhvhfK2oOZZ2lK+dpvRg=
github.com/cockroachdb/sentry-go v0.6.1-cockroachdb.2/go.mod h1:8BT+cPK6xvFOcRlk0R8eg+OTkcqI6baNH4xAkpiYVvQ=
github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE/e/2PUdi/liOCUjSTXgM1o87ZssimdTWN964YiIeI=
github.com/codeclysm/extract/v3 v3.0.2 h1:sB4LcE3Php7LkhZwN0n2p8GCwZe92PEQutdbGURf5xc=
github.com/codeclysm/extract/v3 v3.0.2/go.mod h1:NKsw+hqua9H+Rlwy/w/3Qgt9jDonYEgB6wJu+25eOKw=
Expand Down Expand Up @@ -263,6 +264,7 @@ github.com/davidlazar/go-crypto v0.0.0-20200604182044-b73af7476f6c/go.mod h1:6Uh
github.com/deckarep/golang-set/v2 v2.1.0 h1:g47V4Or+DUdzbs8FxCCmgb6VYd+ptPAngjM6dtGktsI=
github.com/deckarep/golang-set/v2 v2.1.0/go.mod h1:VAky9rY/yGXJOLEDv3OMci+7wtDpOF4IN+y82NBOac4=
github.com/decred/dcrd/crypto/blake256 v1.0.0 h1:/8DMNYp9SGi5f0w7uCm6d6M4OU2rGFK09Y2A4Xv7EE0=
github.com/decred/dcrd/crypto/blake256 v1.0.0/go.mod h1:sQl2p6Y26YV+ZOcSTP6thNdn47hh8kt6rqSlvmrXFAc=
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.1.0 h1:HbphB4TFFXpv7MNrT52FGrrgVXF1owhMVTHFZIlnvd4=
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.1.0/go.mod h1:DZGJHZMqrU4JJqFAWUS2UO1+lbSKsdiOoYi9Zzey7Fc=
github.com/decred/dcrd/lru v1.0.0/go.mod h1:mxKOwFd7lFjN2GZYsiz/ecgqR6kkYAl+0pz0tEMk218=
Expand Down Expand Up @@ -378,6 +380,7 @@ github.com/go-ldap/ldap v3.0.2+incompatible/go.mod h1:qfd9rJvER9Q0/D/Sqn1DfHRoBp
github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE=
github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk=
github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A=
github.com/go-logfmt/logfmt v0.5.1/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs=
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/logr v1.2.3 h1:2DntVwHkVopvECVRSlL5PSo9eG+cAkDCuckLubN+rq0=
github.com/go-logr/logr v1.2.3/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
Expand Down Expand Up @@ -595,8 +598,10 @@ github.com/hashicorp/go.net v0.0.1/go.mod h1:hjKkEWcCURg++eb33jQU7oqQcI9XDCnUzHA
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hashicorp/golang-lru v0.5.4/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4=
github.com/hashicorp/golang-lru v0.5.5-0.20210104140557-80c98217689d h1:dg1dEPuWpEqDnvIw251EVy4zlP8gWbsGj4BsUKCRpYs=
github.com/hashicorp/golang-lru v0.5.5-0.20210104140557-80c98217689d/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4=
github.com/hashicorp/golang-lru v1.0.2 h1:dV3g9Z/unq5DpblPpw+Oqcv4dU/1omnb4Ok8iPY6p1c=
github.com/hashicorp/golang-lru v1.0.2/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4=
github.com/hashicorp/golang-lru/v2 v2.0.1 h1:5pv5N1lT1fjLg2VQ5KWc7kmucp2x/kvFOnxuVTqZ6x4=
github.com/hashicorp/golang-lru/v2 v2.0.1/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM=
github.com/hashicorp/golang-lru/v2 v2.0.2 h1:Dwmkdr5Nc/oBiXgJS3CDHNhJtIHkuZ3DZF5twqnfBdU=
github.com/hashicorp/golang-lru/v2 v2.0.2/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM=
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
Expand Down Expand Up @@ -868,6 +873,7 @@ github.com/json-iterator/go v1.1.8/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/u
github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk=
github.com/jtolds/gls v4.2.1+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
Expand Down Expand Up @@ -1242,6 +1248,7 @@ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJ
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
github.com/moul/http2curl v1.0.0/go.mod h1:8UbvGypXm98wA/IqH45anm5Y2Z6ep6O31QGOAZ3H0fQ=
github.com/mr-tron/base58 v1.1.0/go.mod h1:xcD2VGqlgYjBdcBLw+TuYLr8afG+Hj8g2eTVqeSzSU8=
github.com/mr-tron/base58 v1.1.1/go.mod h1:xcD2VGqlgYjBdcBLw+TuYLr8afG+Hj8g2eTVqeSzSU8=
Expand Down Expand Up @@ -1383,6 +1390,7 @@ github.com/pelletier/go-toml v1.7.0/go.mod h1:vwGMzjaWMwyfHwgIBhI2YUM4fB6nL6lVAv
github.com/pelletier/go-toml/v2 v2.0.5 h1:ipoSadvV8oGUjnUbMub59IDPPwfxF694nG/jwbMiyQg=
github.com/performancecopilot/speed v3.0.0+incompatible/go.mod h1:/CLtqpZ5gBg1M9iaPbIdPPGyKcA8hKdoy6hAWba7Yac=
github.com/petar/GoLLRB v0.0.0-20210522233825-ae3b015fd3e9 h1:1/WtZae0yGtPq+TI6+Tv1WTxkukpXeMlviSxvL7SRgk=
github.com/petar/GoLLRB v0.0.0-20210522233825-ae3b015fd3e9/go.mod h1:x3N5drFsm2uilKKuuYo6LdyD8vZAW55sH/9w+pbo1sw=
github.com/pierrec/lz4 v1.0.2-0.20190131084431-473cd7ce01a1/go.mod h1:3/3N9NVKO0jef7pBehbT1qWhCMrIgbYNnFAZCqQ5LRc=
github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY=
github.com/pierrec/lz4 v2.6.1+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY=
Expand Down Expand Up @@ -1565,6 +1573,8 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/syndtr/goleveldb v1.0.0/go.mod h1:ZVVdQEZoIme9iO1Ch2Jdy24qqXrMMOU6lpPAyBWyWuQ=
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 h1:epCh84lMvA70Z7CTTCmYQn2CKbY8j86K7/FAIr141uY=
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7/go.mod h1:q4W45IWZaF22tdD+VEXcAWRA037jwmWEB5VWYORlTpc=
Expand Down Expand Up @@ -1618,6 +1628,7 @@ github.com/wealdtech/go-merkletree v1.0.0/go.mod h1:cdil512d/8ZC7Kx3bfrDvGMQXB25
github.com/whyrusleeping/base32 v0.0.0-20170828182744-c30ac30633cc h1:BCPnHtcboadS0DvysUuJXZ4lWVv5Bh5i7+tbIyi+ck4=
github.com/whyrusleeping/base32 v0.0.0-20170828182744-c30ac30633cc/go.mod h1:r45hJU7yEoA81k6MWNhpMj/kms0n14dkzkxYHoB96UM=
github.com/whyrusleeping/cbor v0.0.0-20171005072247-63513f603b11 h1:5HZfQkwe0mIfyDmc1Em5GqlNRzcdtlv4HTNmdpt7XH0=
github.com/whyrusleeping/cbor v0.0.0-20171005072247-63513f603b11/go.mod h1:Wlo/SzPmxVp6vXpGt/zaXhHH0fn4IxgqZc82aKg6bpQ=
github.com/whyrusleeping/cbor-gen v0.0.0-20200123233031-1cdf64d27158/go.mod h1:Xj/M2wWU+QdTdRbu/L/1dIZY8/Wb2K9pAhtroQuxJJI=
github.com/whyrusleeping/cbor-gen v0.0.0-20230126041949-52956bd4c9aa h1:EyA027ZAkuaCLoxVX4r1TZMPy1d31fM6hbfQ4OU4I5o=
github.com/whyrusleeping/cbor-gen v0.0.0-20230126041949-52956bd4c9aa/go.mod h1:fgkXqYy7bV2cFeIEOkVTZS/WjXARfBqSH6Q2qHL33hQ=
Expand Down
48 changes: 28 additions & 20 deletions staker/challenge-cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ Use cases:
wavm-module-root-0xab/
message-num-70/
roots.txt
big-step-100/
subchallenge-level-0-big-step-100/
roots.txt
subchallenge-level-1-big-step-100/
roots.txt

We namespace top-level block challenges by wavm module root. Then, we can retrieve
the state roots for any data within a challenge or associated subchallenge based on the hierarchy above.
Expand All @@ -36,7 +38,7 @@ import (
"path/filepath"

protocol "github.com/OffchainLabs/bold/chain-abstraction"
"github.com/OffchainLabs/bold/containers/option"
l2stateprovider "github.com/OffchainLabs/bold/layer2-state-provider"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/log"
)
Expand All @@ -49,11 +51,13 @@ var (
wavmModuleRootPrefix = "wavm-module-root"
messageNumberPrefix = "message-num"
bigStepPrefix = "big-step"
challengeLevelPrefix = "subchallenge-level"
srvlog = log.New("service", "bold-history-commit-cache")
)

// HistoryCommitmentCacher can retrieve history commitment state roots given lookup keys.
type HistoryCommitmentCacher interface {
Get(lookup *Key, readUpTo protocol.Height) ([]common.Hash, error)
Get(lookup *Key, numToRead uint64) ([]common.Hash, error)
Put(lookup *Key, stateRoots []common.Hash) error
}

Expand All @@ -74,23 +78,25 @@ func New(baseDir string) *Cache {
type Key struct {
WavmModuleRoot common.Hash
MessageHeight protocol.Height
BigStepHeight option.Option[protocol.Height]
StepHeights []l2stateprovider.Height
}

// Get a list of state roots from the cache up to a certain index. State roots are saved as files in the directory
// hierarchy for the cache. If a file is not present, ErrNotFoundInCache
// is returned.
func (c *Cache) Get(
lookup *Key,
readUpTo protocol.Height,
numToRead uint64,
) ([]common.Hash, error) {
fName, err := determineFilePath(c.baseDir, lookup)
if err != nil {
return nil, err
}
if _, err := os.Stat(fName); err != nil {
srvlog.Warn("Cache miss", log.Ctx{"fileName": fName})
return nil, ErrNotFoundInCache
}
srvlog.Debug("Cache hit", log.Ctx{"fileName": fName})
f, err := os.Open(fName)
if err != nil {
return nil, err
Expand All @@ -100,7 +106,7 @@ func (c *Cache) Get(
log.Error("Could not close file after reading", "err", err, "file", fName)
}
}()
return readStateRoots(f, readUpTo)
return readStateRoots(f, numToRead)
}

// Put a list of state roots into the cache.
Expand Down Expand Up @@ -149,12 +155,11 @@ func (c *Cache) Put(lookup *Key, stateRoots []common.Hash) error {
}

// Reads 32 bytes at a time from a reader up to a specified height. If none, then read all.
func readStateRoots(r io.Reader, readUpTo protocol.Height) ([]common.Hash, error) {
func readStateRoots(r io.Reader, numToRead uint64) ([]common.Hash, error) {
br := bufio.NewReader(r)
stateRoots := make([]common.Hash, 0)
buf := make([]byte, 0, 32)
totalRead := uint64(0)
for {
for totalRead := uint64(0); totalRead < numToRead; totalRead++ {
n, err := br.Read(buf[:cap(buf)])
if err != nil {
// If we try to read but reach EOF, we break out of the loop.
Expand All @@ -168,15 +173,11 @@ func readStateRoots(r io.Reader, readUpTo protocol.Height) ([]common.Hash, error
return nil, fmt.Errorf("expected to read 32 bytes, got %d bytes", n)
}
stateRoots = append(stateRoots, common.BytesToHash(buf))
if totalRead >= uint64(readUpTo) {
return stateRoots, nil
}
totalRead++
}
if readUpTo >= protocol.Height(len(stateRoots)) {
if protocol.Height(numToRead) > protocol.Height(len(stateRoots)) {
return nil, fmt.Errorf(
"wanted to read up to %d, but only read %d state roots",
readUpTo,
"wanted to read %d roots, but only read %d state roots",
numToRead,
len(stateRoots),
)
}
Expand Down Expand Up @@ -210,16 +211,23 @@ for a given filesystem challenge cache will look as follows:
wavm-module-root-0xab/
message-num-70/
roots.txt
big-step-100/
subchallenge-level-0-big-step-100/
roots.txt
*/
func determineFilePath(baseDir string, lookup *Key) (string, error) {
key := make([]string, 0)
key = append(key, fmt.Sprintf("%s-%s", wavmModuleRootPrefix, lookup.WavmModuleRoot.Hex()))
key = append(key, fmt.Sprintf("%s-%d", messageNumberPrefix, lookup.MessageHeight))
if !lookup.BigStepHeight.IsNone() {
bigStepHeight := lookup.BigStepHeight.Unwrap()
key = append(key, fmt.Sprintf("%s-%d", bigStepPrefix, bigStepHeight))
for challengeLevel, height := range lookup.StepHeights {
key = append(key, fmt.Sprintf(
"%s-%d-%s-%d",
challengeLevelPrefix,
challengeLevel+1, // subchallenges start at 1, as level 0 is the block challenge level.
bigStepPrefix,
height,
),
)

}
key = append(key, stateRootsFileName)
return filepath.Join(baseDir, filepath.Join(key...)), nil
Expand Down
39 changes: 17 additions & 22 deletions staker/challenge-cache/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"os"
"strings"
"testing"

protocol "github.com/OffchainLabs/bold/chain-abstraction"
"github.com/OffchainLabs/bold/containers/option"
l2stateprovider "github.com/OffchainLabs/bold/layer2-state-provider"
"github.com/ethereum/go-ethereum/common"
)

Expand All @@ -33,10 +31,10 @@ func TestCache(t *testing.T) {
key := &Key{
WavmModuleRoot: common.BytesToHash([]byte("foo")),
MessageHeight: 0,
BigStepHeight: option.Some(protocol.Height(0)),
StepHeights: []l2stateprovider.Height{l2stateprovider.Height(0)},
}
t.Run("Not found", func(t *testing.T) {
_, err := cache.Get(key, protocol.Height(0))
_, err := cache.Get(key, 0)
if !errors.Is(err, ErrNotFoundInCache) {
t.Fatal(err)
}
Expand All @@ -55,7 +53,7 @@ func TestCache(t *testing.T) {
if err != nil {
t.Fatal(err)
}
got, err := cache.Get(key, protocol.Height(2))
got, err := cache.Get(key, 3)
if err != nil {
t.Fatal(err)
}
Expand All @@ -72,7 +70,7 @@ func TestCache(t *testing.T) {
func TestReadWriteStateRoots(t *testing.T) {
t.Run("read up to, but had empty reader", func(t *testing.T) {
b := bytes.NewBuffer([]byte{})
_, err := readStateRoots(b, protocol.Height(100))
_, err := readStateRoots(b, 100)
if err == nil {
t.Fatal("Wanted error")
}
Expand All @@ -84,7 +82,7 @@ func TestReadWriteStateRoots(t *testing.T) {
b := bytes.NewBuffer([]byte{})
want := common.BytesToHash([]byte("foo"))
b.Write(want.Bytes())
roots, err := readStateRoots(b, protocol.Height(0))
roots, err := readStateRoots(b, 1)
if err != nil {
t.Fatal(err)
}
Expand All @@ -103,7 +101,7 @@ func TestReadWriteStateRoots(t *testing.T) {
b.Write(foo.Bytes())
b.Write(bar.Bytes())
b.Write(baz.Bytes())
roots, err := readStateRoots(b, protocol.Height(1))
roots, err := readStateRoots(b, 2)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -174,7 +172,7 @@ func Test_readStateRoots(t *testing.T) {
common.BytesToHash([]byte("baz")),
}
m := &mockReader{wantErr: true, roots: want, err: errors.New("foo")}
_, err := readStateRoots(m, protocol.Height(1))
_, err := readStateRoots(m, 1)
if err == nil {
t.Fatal(err)
}
Expand All @@ -189,11 +187,11 @@ func Test_readStateRoots(t *testing.T) {
common.BytesToHash([]byte("baz")),
}
m := &mockReader{wantErr: true, roots: want, err: io.EOF}
_, err := readStateRoots(m, protocol.Height(100))
_, err := readStateRoots(m, 100)
if err == nil {
t.Fatal(err)
}
if !strings.Contains(err.Error(), "wanted to read up to 100, but only read 0 state roots") {
if !strings.Contains(err.Error(), "wanted to read 100") {
t.Fatalf("Unexpected error: %v", err)
}
})
Expand All @@ -204,7 +202,7 @@ func Test_readStateRoots(t *testing.T) {
common.BytesToHash([]byte("baz")),
}
m := &mockReader{wantErr: false, roots: want, bytesRead: 16}
_, err := readStateRoots(m, protocol.Height(2))
_, err := readStateRoots(m, 2)
if err == nil {
t.Fatal(err)
}
Expand All @@ -219,7 +217,7 @@ func Test_readStateRoots(t *testing.T) {
common.BytesToHash([]byte("baz")),
}
m := &mockReader{wantErr: false, roots: want, bytesRead: 32}
got, err := readStateRoots(m, protocol.Height(2))
got, err := readStateRoots(m, 3)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -252,7 +250,7 @@ func Test_determineFilePath(t *testing.T) {
baseDir: "",
key: &Key{
MessageHeight: 100,
BigStepHeight: option.Some(protocol.Height(50)),
StepHeights: []l2stateprovider.Height{l2stateprovider.Height(50)},
},
},
want: "wavm-module-root-0x0000000000000000000000000000000000000000000000000000000000000000/message-num-100/big-step-50/state-roots",
Expand Down Expand Up @@ -283,10 +281,7 @@ func Test_determineFilePath(t *testing.T) {

func BenchmarkCache_Read_32Mb(b *testing.B) {
b.StopTimer()
basePath, err := ioutil.TempDir("", "*")
if err != nil {
b.Fatal(err)
}
basePath := os.TempDir()
if err := os.MkdirAll(basePath, os.ModePerm); err != nil {
b.Fatal(err)
}
Expand All @@ -299,19 +294,19 @@ func BenchmarkCache_Read_32Mb(b *testing.B) {
key := &Key{
WavmModuleRoot: common.BytesToHash([]byte("foo")),
MessageHeight: 0,
BigStepHeight: option.Some(protocol.Height(0)),
StepHeights: []l2stateprovider.Height{l2stateprovider.Height(0)},
}
numRoots := 1 << 20
roots := make([]common.Hash, numRoots)
for i := range roots {
roots[i] = common.BytesToHash([]byte(fmt.Sprintf("%d", i)))
}
if err = cache.Put(key, roots); err != nil {
if err := cache.Put(key, roots); err != nil {
b.Fatal(err)
}
b.StartTimer()
for i := 0; i < b.N; i++ {
readUpTo := protocol.Height(1 << 20)
readUpTo := uint64(1 << 20)
roots, err := cache.Get(key, readUpTo)
if err != nil {
b.Fatal(err)
Expand Down
Loading
Loading