-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement reorg implementation and trigger reorg
- Loading branch information
1 parent
14ef44f
commit e1736fe
Showing
13 changed files
with
189 additions
and
148 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,63 @@ | ||
package consensus | ||
|
||
import ( | ||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/lukso-network/lukso-orchestrator/shared/types" | ||
"github.com/pkg/errors" | ||
"sync/atomic" | ||
) | ||
|
||
// processReorg | ||
func (s *Service) processReorg(parentVanBlkHash common.Hash) error { | ||
atomic.StoreUint32(&s.reorgInProgress, 1) | ||
defer func() { | ||
atomic.StoreUint32(&s.reorgInProgress, 0) | ||
}() | ||
|
||
finalizedSlot := s.db.FinalizedSlot() | ||
finalizedStepId, err := s.db.GetStepIdBySlot(finalizedSlot) | ||
if err != nil { | ||
log.WithError(err).WithField("finalizedSlot", finalizedSlot).WithField("latestFinalizedStepId", finalizedStepId). | ||
Error("Could not found step id from DB") | ||
return err | ||
} | ||
|
||
latestStepId := s.db.LatestStepID() | ||
parentShardInfo, err := s.db.FindAncestor(latestStepId, finalizedStepId, parentVanBlkHash) | ||
if err != nil || parentShardInfo == nil { | ||
log.WithField("finalizedSlot", finalizedSlot).WithField("latestFinalizedStepId", finalizedStepId). | ||
Error("Could not found parent shard info from DB") | ||
return errors.Wrap(errUnknownParent, "Failed to process reorg") | ||
} | ||
|
||
if len(parentShardInfo.Shards) == 0 || len(parentShardInfo.Shards[0].Blocks) == 0 { | ||
log.WithField("finalizedSlot", finalizedSlot).WithField("latestFinalizedStepId", finalizedStepId). | ||
Error("Invalid length of shards in parent shard info") | ||
return errors.Wrap(errUnknownParent, "Failed to process reorg") | ||
} | ||
|
||
if err := s.db.RemoveShardingInfos(finalizedStepId + 1); err != nil { | ||
log.WithError(err).Error("Could not revert shard info from DB during reorg") | ||
return err | ||
} | ||
|
||
if err := s.db.SaveLatestStepID(finalizedStepId); err != nil { | ||
log.WithError(err).Error("Could not store latest step id during reorg") | ||
return err | ||
} | ||
|
||
// Removing slot infos from vanguard cache and pandora cache | ||
s.vanguardPendingShardingCache.Purge() | ||
s.pandoraPendingHeaderCache.Purge() | ||
|
||
reorgInfo := &types.Reorg{ | ||
VanParentHash: parentShardInfo.SlotInfo.BlockRoot.Bytes(), | ||
PanParentHash: parentShardInfo.Shards[0].Blocks[0].HeaderRoot.Bytes(), | ||
} | ||
|
||
// disconnect subscription | ||
s.pandoraService.Resubscribe() | ||
s.vanguardService.StopSubscription(reorgInfo) | ||
|
||
return nil | ||
} |
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
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.