-
Notifications
You must be signed in to change notification settings - Fork 0
Feature/slashing #122
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
Open
s-h-ubham
wants to merge
14
commits into
develop
Choose a base branch
from
feature/slashing
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Feature/slashing #122
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
f636243
feta:add double signing for slashing
NodeNavigator 8a9e197
WIP: added logs and staking contract
s-h-ubham 07129e5
WIP: added system transaction to interact with the contract
s-h-ubham 2cb0316
WIP: Updated slashing logic to create and process a separate state tr…
s-h-ubham df42064
WIP: updated logs for slashing
s-h-ubham 3417bfc
WIP: deploy the contract through a transaction included in the block
s-h-ubham 8b556a6
WIP: contract deployment at fork block runs during both production an…
s-h-ubham 4979c30
WIP: added the the slashing contract in the readContracts array
s-h-ubham cf446cc
WIP: added SlashValidatorSlashingFn, initialize Slashing contract & a…
s-h-ubham a5feb3f
Fix: state root mismatch issues by ensuring identical deployment acro…
s-h-ubham f398b39
chore: implement double signing detection and slashing transaction cr…
s-h-ubham 7b0a13c
chore: implement slashing contract with upgradeable pattern and prope…
s-h-ubham 449c55f
chore: correct contract initialization and caller roles for slashing …
s-h-ubham 1489a78
fix: fix error in test cases
s-h-ubham File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,18 @@ | ||
| package common | ||
|
|
||
| import ( | ||
| "github.com/0xPolygon/polygon-edge/types" | ||
| bolt "go.etcd.io/bbolt" | ||
| ) | ||
|
|
||
| type PostBlockRequest struct { | ||
| // FullBlock is a reference of the executed block | ||
| FullBlock *types.FullBlock | ||
| // Epoch is the epoch number of the executed block | ||
| Epoch uint64 | ||
| // IsEpochEndingBlock indicates if this was the last block of given epoch | ||
| IsEpochEndingBlock bool | ||
| // DBTx is the opened transaction on state store (in our case boltDB) | ||
| // used to save necessary data on PostBlock | ||
| DBTx *bolt.Tx | ||
| } |
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -19,6 +19,8 @@ import ( | |
| "github.com/0xPolygon/polygon-edge/types" | ||
| bolt "go.etcd.io/bbolt" | ||
|
|
||
| "github.com/0xPolygon/polygon-edge/consensus/polybft/common" | ||
| "github.com/0xPolygon/polygon-edge/consensus/polybft/slashing" | ||
| "github.com/Hydra-Chain/go-ibft/messages" | ||
| "github.com/Hydra-Chain/go-ibft/messages/proto" | ||
| hcf "github.com/hashicorp/go-hclog" | ||
|
|
@@ -130,6 +132,8 @@ type consensusRuntime struct { | |
| // rewardWalletCalculator is the object which handles the calculation of the required HYDRA | ||
| // that needs to be sent to the reward in order to have enough funds | ||
| rewardWalletCalculator RewardWalletCalculator | ||
| // doubleSigningTracker tracks IBFT messages and detects double signing | ||
| doubleSigningTracker slashing.DoubleSigningTracker | ||
| } | ||
|
|
||
| // newConsensusRuntime creates and starts a new consensus runtime instance with event tracking | ||
|
|
@@ -250,6 +254,20 @@ func (c *consensusRuntime) initStakeManager(logger hcf.Logger, dbTx *bolt.Tx) er | |
| return err | ||
| } | ||
|
|
||
| // initDoubleSigningTracker initializes double signing tracker | ||
| // | ||
| // (which is used for creating slashing evidence). | ||
| func (c *consensusRuntime) initDoubleSigningTracker(logger hcf.Logger, store *StakeStore) error { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This method is unused |
||
| tracker, err := slashing.NewDoubleSigningTracker(logger.Named("double_sign_tracker"), store) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to initialize double signing tracker: %w", err) | ||
| } | ||
|
|
||
| c.doubleSigningTracker = tracker | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| // getGuardedData returns last build block, proposer snapshot and current epochMetadata in a thread-safe manner. | ||
| func (c *consensusRuntime) getGuardedData() (guardedDataDTO, error) { | ||
| c.lock.RLock() | ||
|
|
@@ -366,6 +384,19 @@ func (c *consensusRuntime) OnBlockInserted(fullBlock *types.FullBlock) { | |
| c.logger.Error("post block callback failed in state sync relayer", "err", err) | ||
| } | ||
|
|
||
| // handle double signing tracker events that happened in block | ||
| if c.doubleSigningTracker != nil { | ||
| commonPostBlock := &common.PostBlockRequest{ | ||
| FullBlock: fullBlock, | ||
| Epoch: epoch.Number, | ||
| IsEpochEndingBlock: isEndOfEpoch, | ||
| DBTx: dbTx, | ||
| } | ||
| if err := c.doubleSigningTracker.PostBlock(commonPostBlock); err != nil { | ||
| c.logger.Error("post block callback failed in double signing tracker", "err", err) | ||
| } | ||
| } | ||
|
|
||
| if isEndOfEpoch { | ||
| if epoch, err = c.restartEpoch(fullBlock.Block.Header, dbTx); err != nil { | ||
| c.logger.Error("failed to restart epoch after block inserted", "error", err) | ||
|
|
@@ -456,9 +487,18 @@ func (c *consensusRuntime) FSM() error { | |
| isEndOfSprint: isEndOfSprint, | ||
| isStartOfEpoch: isStartOfEpoch, | ||
| proposerSnapshot: proposerSnapshot, | ||
| forks: c.config.consensusConfig.Params.Forks, | ||
| logger: c.logger.Named("fsm"), | ||
| } | ||
|
|
||
| // Populate double signers for the parent block | ||
| if c.doubleSigningTracker != nil { | ||
| ff.doubleSigners = c.doubleSigningTracker.GetDoubleSigners(parent.Number) | ||
| if len(ff.doubleSigners) > 0 { | ||
| c.logger.Info("Found double signers", "block", parent.Number, "doubleSigners", ff.doubleSigners) | ||
| } | ||
| } | ||
|
|
||
| if isEndOfSprint { | ||
| commitment, err := c.stateSyncManager.Commitment(pendingBlockNumber) | ||
| if err != nil { | ||
|
|
@@ -752,6 +792,11 @@ func (c *consensusRuntime) GetStateSyncProof(stateSyncID uint64) (types.Proof, e | |
| return c.stateSyncManager.GetStateSyncProof(stateSyncID) | ||
| } | ||
|
|
||
| // GetPendingSlashProofs retrieves executable slashing exit event proofs | ||
| func (c *consensusRuntime) GetPendingSlashProofs() ([]types.Proof, error) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is unused? |
||
| return c.checkpointManager.GenerateSlashExitProofs() | ||
| } | ||
|
|
||
| // setIsActiveValidator updates the activeValidatorFlag field | ||
| func (c *consensusRuntime) setIsActiveValidator(isActiveValidator bool) { | ||
| c.activeValidatorFlag.Store(isActiveValidator) | ||
|
|
||
This file contains hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't support the IBFT consensus, so no need to make updates there