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

feat(L1 state manager): L1Reader #1018

Closed
wants to merge 30 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
00494d5
feat: follower node sync from DA #631
jonastheis Aug 29, 2024
11e440b
fixes after merge
jonastheis Aug 29, 2024
2ee38fd
fix: panic after startup due to misconfigured api
jonastheis Aug 29, 2024
9e8afc4
fix bug of not calculating block state root
NazariiDenha Aug 29, 2024
6068db3
minor adjustment of fix
jonastheis Aug 29, 2024
117016e
add l1_tracker and l1_reader without caching
NazariiDenha Sep 1, 2024
271b7dc
fix incorrect depth calc
NazariiDenha Sep 2, 2024
f9111cb
refactor: rename package to `l1`
jonastheis Sep 3, 2024
0fc3b94
refactor reader to process raw logs to rollup events
NazariiDenha Sep 3, 2024
5b22f7f
refactor da_syncer to not use depend on rollup_sync_service and sync_…
NazariiDenha Sep 3, 2024
27c5d63
feat: implement tracker
jonastheis Sep 4, 2024
fa09f3f
fetch in batches
NazariiDenha Sep 4, 2024
6686d1d
feat: add test cases for happy path and fix minor bugs uncovered by t…
jonastheis Sep 5, 2024
15ea17e
feat: add test for confirmation rules when subscribing
jonastheis Sep 5, 2024
dbafb2c
add extensive tests for reorgs
jonastheis Sep 6, 2024
10a8b64
adjust interface to be the same as reth ex ex but with block headers
jonastheis Sep 25, 2024
854dc43
fixes
NazariiDenha Oct 6, 2024
294b9c6
pruning
NazariiDenha Oct 7, 2024
6464296
Merge remote-tracking branch 'origin/syncUpstream/active' into feat/l…
jonastheis Oct 23, 2024
79842f8
fixes after merge
jonastheis Oct 23, 2024
a45885e
extend Reader
jonastheis Oct 23, 2024
1b5a4f8
simplify as functionality has been moved to Reader
jonastheis Oct 23, 2024
acb1bc2
Merge remote-tracking branch 'origin/syncUpstream/active' into feat/l…
jonastheis Oct 24, 2024
591534c
fix using outdated ABI for L1MessageQueue
jonastheis Oct 24, 2024
c96a3da
Add LatestFinalizedBatch
jonastheis Oct 28, 2024
113241e
Fix bug in queryInBatches
jonastheis Oct 28, 2024
e873ac0
add HeapMap component
jonastheis Oct 29, 2024
bbd7144
remove state tracker and move to separate branch
jonastheis Nov 28, 2024
b895b43
add some tests
jonastheis Nov 28, 2024
31f0bfe
Merge remote-tracking branch 'origin/syncUpstream/active' into feat/l…
jonastheis Nov 28, 2024
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
90 changes: 90 additions & 0 deletions common/heapmap.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package common

type HeapMap[K comparable, T Comparable[T]] struct {
h *Heap[T]
m *ShrinkingMap[K, *HeapElement[T]]
keyFromElement func(T) K
}

func NewHeapMap[K comparable, T Comparable[T]](keyFromElement func(T) K) *HeapMap[K, T] {
return &HeapMap[K, T]{
h: NewHeap[T](),
m: NewShrinkingMap[K, *HeapElement[T]](1000),
keyFromElement: keyFromElement,
}
}

func (hm *HeapMap[K, T]) Len() int {
return hm.h.Len()
}

func (hm *HeapMap[K, T]) Push(element T) bool {
k := hm.keyFromElement(element)

if hm.m.Has(k) {
return false
}

heapElement := hm.h.Push(element)
hm.m.Set(k, heapElement)

return true
}

func (hm *HeapMap[K, T]) Pop() T {
element := hm.h.Pop()
k := hm.keyFromElement(element.Value())
hm.m.Delete(k)

return element.Value()
}

func (hm *HeapMap[K, T]) Peek() T {
return hm.h.Peek().Value()
}

func (hm *HeapMap[K, T]) RemoveByElement(element T) bool {
key := hm.keyFromElement(element)
heapElement, exists := hm.m.Get(key)
if !exists {
return false
}

hm.h.Remove(heapElement)
hm.m.Delete(key)

return true
}

func (hm *HeapMap[K, T]) RemoveByKey(key K) bool {
heapElement, exists := hm.m.Get(key)
if !exists {
return false
}

hm.h.Remove(heapElement)
hm.m.Delete(key)

return true
}

func (hm *HeapMap[K, T]) Clear() {
hm.h.Clear()
hm.m = NewShrinkingMap[K, *HeapElement[T]](1000)
}

func (hm *HeapMap[K, T]) Keys() []K {
return hm.m.Keys()
}

func (hm *HeapMap[K, T]) Elements() []T {
var elements []T
for _, element := range hm.m.Values() {
elements = append(elements, element.Value())
}
return elements
}

func (hm *HeapMap[K, T]) Has(element T) bool {
return hm.m.Has(hm.keyFromElement(element))
}
16 changes: 16 additions & 0 deletions common/shrinkingmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,22 @@ func (s *ShrinkingMap[K, V]) Has(key K) bool {
return exists
}

func (s *ShrinkingMap[K, V]) Keys() []K {
var keys []K
for k := range s.m {
keys = append(keys, k)
}
return keys
}

func (s *ShrinkingMap[K, V]) Values() []V {
var values []V
for _, v := range s.m {
values = append(values, v)
}
return values
}

func (s *ShrinkingMap[K, V]) Delete(key K) (deleted bool) {
if _, exists := s.m[key]; !exists {
return false
Expand Down
3 changes: 2 additions & 1 deletion eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ import (
"github.com/scroll-tech/go-ethereum/rlp"
"github.com/scroll-tech/go-ethereum/rollup/ccc"
"github.com/scroll-tech/go-ethereum/rollup/da_syncer"
"github.com/scroll-tech/go-ethereum/rollup/l1"
"github.com/scroll-tech/go-ethereum/rollup/rollup_sync_service"
"github.com/scroll-tech/go-ethereum/rollup/sync_service"
"github.com/scroll-tech/go-ethereum/rpc"
Expand Down Expand Up @@ -113,7 +114,7 @@ type Ethereum struct {

// New creates a new Ethereum object (including the
// initialisation of the common Ethereum object)
func New(stack *node.Node, config *ethconfig.Config, l1Client sync_service.EthClient) (*Ethereum, error) {
func New(stack *node.Node, config *ethconfig.Config, l1Client l1.Client) (*Ethereum, error) {
// Ensure configuration values are compatible and sane
if config.SyncMode == downloader.LightSync {
return nil, errors.New("can't run eth.Ethereum in light sync mode, use les.LightEthereum")
Expand Down
16 changes: 4 additions & 12 deletions rollup/da_syncer/blob_client/beacon_node_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,10 @@ import (

"github.com/scroll-tech/go-ethereum/common"
"github.com/scroll-tech/go-ethereum/crypto/kzg4844"
"github.com/scroll-tech/go-ethereum/rollup/rollup_sync_service"
)

type BeaconNodeClient struct {
apiEndpoint string
l1Client *rollup_sync_service.L1Client
genesisTime uint64
secondsPerSlot uint64
}
Expand All @@ -28,7 +26,7 @@ var (
beaconNodeBlobEndpoint = "/eth/v1/beacon/blob_sidecars"
)

func NewBeaconNodeClient(apiEndpoint string, l1Client *rollup_sync_service.L1Client) (*BeaconNodeClient, error) {
func NewBeaconNodeClient(apiEndpoint string) (*BeaconNodeClient, error) {
// get genesis time
genesisPath, err := url.JoinPath(apiEndpoint, beaconNodeGenesisEndpoint)
if err != nil {
Expand Down Expand Up @@ -94,19 +92,13 @@ func NewBeaconNodeClient(apiEndpoint string, l1Client *rollup_sync_service.L1Cli

return &BeaconNodeClient{
apiEndpoint: apiEndpoint,
l1Client: l1Client,
genesisTime: genesisTime,
secondsPerSlot: secondsPerSlot,
}, nil
}

func (c *BeaconNodeClient) GetBlobByVersionedHashAndBlockNumber(ctx context.Context, versionedHash common.Hash, blockNumber uint64) (*kzg4844.Blob, error) {
// get block timestamp to calculate slot
header, err := c.l1Client.GetHeaderByNumber(blockNumber)
if err != nil {
return nil, fmt.Errorf("failed to get header by number, err: %w", err)
}
slot := (header.Time - c.genesisTime) / c.secondsPerSlot
func (c *BeaconNodeClient) GetBlobByVersionedHashAndBlockTime(ctx context.Context, versionedHash common.Hash, blockTime uint64) (*kzg4844.Blob, error) {
slot := (blockTime - c.genesisTime) / c.secondsPerSlot

// get blob sidecar for slot
blobSidecarPath, err := url.JoinPath(c.apiEndpoint, beaconNodeBlobEndpoint, fmt.Sprintf("%d", slot))
Expand Down Expand Up @@ -156,7 +148,7 @@ func (c *BeaconNodeClient) GetBlobByVersionedHashAndBlockNumber(ctx context.Cont
}
}

return nil, fmt.Errorf("missing blob %v in slot %d, block number %d", versionedHash, slot, blockNumber)
return nil, fmt.Errorf("missing blob %v in slot %d", versionedHash, slot)
}

type GenesisResp struct {
Expand Down
6 changes: 3 additions & 3 deletions rollup/da_syncer/blob_client/blob_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const (
)

type BlobClient interface {
GetBlobByVersionedHashAndBlockNumber(ctx context.Context, versionedHash common.Hash, blockNumber uint64) (*kzg4844.Blob, error)
GetBlobByVersionedHashAndBlockTime(ctx context.Context, versionedHash common.Hash, blockTime uint64) (*kzg4844.Blob, error)
}

type BlobClients struct {
Expand All @@ -32,13 +32,13 @@ func NewBlobClients(blobClients ...BlobClient) *BlobClients {
}
}

func (c *BlobClients) GetBlobByVersionedHashAndBlockNumber(ctx context.Context, versionedHash common.Hash, blockNumber uint64) (*kzg4844.Blob, error) {
func (c *BlobClients) GetBlobByVersionedHashAndBlockTime(ctx context.Context, versionedHash common.Hash, blockTime uint64) (*kzg4844.Blob, error) {
if len(c.list) == 0 {
return nil, fmt.Errorf("BlobClients.GetBlobByVersionedHash: list of BlobClients is empty")
}

for i := 0; i < len(c.list); i++ {
blob, err := c.list[c.curPos].GetBlobByVersionedHashAndBlockNumber(ctx, versionedHash, blockNumber)
blob, err := c.list[c.curPos].GetBlobByVersionedHashAndBlockTime(ctx, versionedHash, blockTime)
if err == nil {
return blob, nil
}
Expand Down
2 changes: 1 addition & 1 deletion rollup/da_syncer/blob_client/blob_scan_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func NewBlobScanClient(apiEndpoint string) *BlobScanClient {
}
}

func (c *BlobScanClient) GetBlobByVersionedHashAndBlockNumber(ctx context.Context, versionedHash common.Hash, blockNumber uint64) (*kzg4844.Blob, error) {
func (c *BlobScanClient) GetBlobByVersionedHashAndBlockTime(ctx context.Context, versionedHash common.Hash, blockTime uint64) (*kzg4844.Blob, error) {
// blobscan api docs https://api.blobscan.com/#/blobs/blob-getByBlobId
path, err := url.JoinPath(c.apiEndpoint, versionedHash.String())
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion rollup/da_syncer/blob_client/block_native_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func NewBlockNativeClient(apiEndpoint string) *BlockNativeClient {
}
}

func (c *BlockNativeClient) GetBlobByVersionedHashAndBlockNumber(ctx context.Context, versionedHash common.Hash, blockNumber uint64) (*kzg4844.Blob, error) {
func (c *BlockNativeClient) GetBlobByVersionedHashAndBlockTime(ctx context.Context, versionedHash common.Hash, blockTime uint64) (*kzg4844.Blob, error) {
// blocknative api docs https://docs.blocknative.com/blocknative-data-archive/blob-archive
path, err := url.JoinPath(c.apiEndpoint, versionedHash.String())
if err != nil {
Expand Down
Loading
Loading