-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
7263154
commit 89ee9a9
Showing
10 changed files
with
136 additions
and
18 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,16 @@ | ||
package entities | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
) | ||
|
||
type LastExecutionData struct { | ||
SyncVersion string | ||
LastStart time.Time | ||
Configuration string | ||
} | ||
|
||
func (s *LastExecutionData) String() string { | ||
return fmt.Sprintf("{SyncVersion: %s, LastStart: %s}", s.SyncVersion, s.LastStart.String()) | ||
} |
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,58 @@ | ||
package model | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
"github.com/0xPolygonHermez/zkevm-synchronizer-l1/log" | ||
"github.com/0xPolygonHermez/zkevm-synchronizer-l1/state/entities" | ||
) | ||
|
||
type LastExecutionState struct { | ||
storage storageKVInterface | ||
lastExecutionCache *lastExecutionBoundData | ||
currentExecution *lastExecutionBoundData | ||
} | ||
|
||
type lastExecutionBoundData = entities.LastExecutionData | ||
|
||
func NewLastExecutionState(storage storageKVInterface, | ||
configString string, syncVesion string) *LastExecutionState { | ||
res := &LastExecutionState{ | ||
storage: storage, | ||
} | ||
last, err := res.getCurrentExecutionData(context.Background(), nil, storage) | ||
if err != nil { | ||
log.Error("Error getting current execution data", "error", err) | ||
return nil | ||
} | ||
res.lastExecutionCache = last | ||
res.currentExecution = &lastExecutionBoundData{ | ||
Configuration: configString, | ||
SyncVersion: syncVesion, | ||
} | ||
|
||
return res | ||
} | ||
|
||
func (l *LastExecutionState) GetPreviousExecutionData(ctx context.Context, dbTx storageTxType, storage storageKVInterface) (*lastExecutionBoundData, error) { | ||
return l.lastExecutionCache, nil | ||
} | ||
|
||
func (l *LastExecutionState) StartingSynchronization(ctx context.Context, dbTx storageTxType) error { | ||
l.currentExecution.LastStart = time.Now() | ||
return l.SetCurrentExecutionData(ctx, dbTx, l.storage, l.currentExecution) | ||
} | ||
|
||
func (l *LastExecutionState) SetCurrentExecutionData(ctx context.Context, dbTx storageTxType, storage storageKVInterface, data *lastExecutionBoundData) error { | ||
err := l.storage.KVSetJson(ctx, keyStorageLastExecution, data, nil, dbTx) | ||
if err != nil { | ||
return err | ||
} | ||
l.lastExecutionCache = data | ||
return nil | ||
} | ||
|
||
func (l *LastExecutionState) getCurrentExecutionData(ctx context.Context, dbTx storageTxType, storage storageKVInterface) (*lastExecutionBoundData, error) { | ||
return GetKVHelper[lastExecutionBoundData](ctx, keyStorageLastExecution, storage, dbTx) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package syncinterfaces | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/0xPolygonHermez/zkevm-synchronizer-l1/state/entities" | ||
) | ||
|
||
type LastExecutionChecker interface { | ||
StartingSynchronization(ctx context.Context, dbTx entities.Tx) error | ||
} |
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