forked from 0xPolygonHermez/zkevm-node
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix/3164 eth syncing dont return expected values (0xPolygonHermez#3165)…
- Loading branch information
1 parent
d6d4b96
commit 1dfa467
Showing
8 changed files
with
294 additions
and
65 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
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
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 |
---|---|---|
@@ -1,14 +1,64 @@ | ||
package state | ||
|
||
// SyncingInfo stores information regarding the syncing status of the node | ||
type SyncingInfo struct { | ||
InitialSyncingBlock uint64 | ||
LastBlockNumberSeen uint64 | ||
LastBlockNumberConsolidated uint64 | ||
CurrentBlockNumber uint64 | ||
import ( | ||
"context" | ||
"errors" | ||
|
||
"github.com/jackc/pgx/v4" | ||
) | ||
|
||
// SyncInfoDataOnStorage stores information regarding the syncing status of the node in the database | ||
type SyncInfoDataOnStorage struct { | ||
InitialSyncingBatch uint64 | ||
LastBatchNumberSeen uint64 | ||
LastBatchNumberConsolidated uint64 | ||
CurrentBatchNumber uint64 | ||
} | ||
|
||
// SyncingInfo stores information regarding the syncing status of the node | ||
type SyncingInfo struct { | ||
InitialSyncingBlock uint64 // L2Block corresponding to InitialSyncingBatch | ||
CurrentBlockNumber uint64 // last L2Block in state | ||
EstimatedHighestBlock uint64 // estimated highest L2Block in state | ||
|
||
// IsSynchronizing indicates if the node is syncing (true -> syncing, false -> fully synced) | ||
IsSynchronizing bool | ||
} | ||
|
||
// GetSyncingInfo returns information regarding the syncing status of the node | ||
func (p *State) GetSyncingInfo(ctx context.Context, dbTx pgx.Tx) (SyncingInfo, error) { | ||
var info SyncingInfo | ||
|
||
syncData, err := p.GetSyncInfoData(ctx, dbTx) | ||
if errors.Is(err, ErrNotFound) { | ||
return SyncingInfo{}, ErrStateNotSynchronized | ||
} else if err != nil { | ||
return SyncingInfo{}, err | ||
} | ||
|
||
info.InitialSyncingBlock, err = p.GetFirstL2BlockNumberForBatchNumber(ctx, syncData.InitialSyncingBatch, dbTx) | ||
if errors.Is(err, ErrNotFound) { | ||
return SyncingInfo{}, ErrStateNotSynchronized | ||
} else if err != nil { | ||
return SyncingInfo{}, err | ||
} | ||
|
||
lastBlockNumber, err := p.GetLastL2BlockNumber(ctx, dbTx) | ||
if errors.Is(err, ErrNotFound) { | ||
return SyncingInfo{}, ErrStateNotSynchronized | ||
} else if err != nil { | ||
return SyncingInfo{}, err | ||
} | ||
info.CurrentBlockNumber = lastBlockNumber | ||
|
||
lastBatchNumber, err := p.GetLastBatchNumber(ctx, dbTx) | ||
if errors.Is(err, ErrNotFound) { | ||
return SyncingInfo{}, ErrStateNotSynchronized | ||
} else if err != nil { | ||
return SyncingInfo{}, err | ||
} | ||
|
||
info.EstimatedHighestBlock = ^uint64(0) | ||
info.IsSynchronizing = syncData.LastBatchNumberSeen > lastBatchNumber | ||
|
||
return info, nil | ||
} |
Oops, something went wrong.