-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- part 1 of #13384 (adding eon based validation of decryption keys) - part 2 will be to use the eon info to validate the keys - takes a chunk of changes out of bigger branch #13553
- Loading branch information
Showing
13 changed files
with
1,137 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// Copyright 2025 The Erigon Authors | ||
// This file is part of Erigon. | ||
// | ||
// Erigon is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Lesser General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Erigon is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Lesser General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Lesser General Public License | ||
// along with Erigon. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
package shutter | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/erigontech/erigon-lib/event" | ||
"github.com/erigontech/erigon-lib/gointerfaces/remoteproto" | ||
"github.com/erigontech/erigon-lib/log/v3" | ||
) | ||
|
||
type BlockEvent struct { | ||
BlockNum uint64 | ||
Unwind bool | ||
} | ||
|
||
type BlockListener struct { | ||
logger log.Logger | ||
stateChangesClient stateChangesClient | ||
events *event.Observers[BlockEvent] | ||
} | ||
|
||
func NewBlockListener(logger log.Logger, stateChangesClient stateChangesClient) BlockListener { | ||
return BlockListener{ | ||
logger: logger, | ||
stateChangesClient: stateChangesClient, | ||
events: event.NewObservers[BlockEvent](), | ||
} | ||
} | ||
|
||
func (bl BlockListener) RegisterObserver(o event.Observer[BlockEvent]) event.UnregisterFunc { | ||
return bl.events.Register(o) | ||
} | ||
|
||
func (bl BlockListener) Run(ctx context.Context) error { | ||
bl.logger.Info("running block listener") | ||
|
||
sub, err := bl.stateChangesClient.StateChanges(ctx, &remoteproto.StateChangeRequest{}) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// note the changes stream is ctx-aware so Recv should terminate with err if ctx gets done | ||
var batch *remoteproto.StateChangeBatch | ||
for batch, err = sub.Recv(); err != nil; batch, err = sub.Recv() { | ||
if batch == nil || len(batch.ChangeBatch) == 0 { | ||
continue | ||
} | ||
|
||
latestChange := batch.ChangeBatch[len(batch.ChangeBatch)-1] | ||
blockEvent := BlockEvent{ | ||
BlockNum: latestChange.BlockHeight, | ||
Unwind: latestChange.Direction == remoteproto.Direction_UNWIND, | ||
} | ||
|
||
bl.events.NotifySync(blockEvent) | ||
} | ||
|
||
return err | ||
} |
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.