Skip to content

Commit

Permalink
consortium/v2: integrate with the finality tracking contract
Browse files Browse the repository at this point in the history
This commit integrates with the finality tracking contract
(axieinfinity/ronin-dpos-contracts#279) to record the
finality reward for voters.
  • Loading branch information
minh-bq committed Aug 30, 2023
1 parent 1663c7a commit d3cfddf
Show file tree
Hide file tree
Showing 3 changed files with 220 additions and 3 deletions.
12 changes: 10 additions & 2 deletions consensus/consortium/common/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/common/math"
"github.com/ethereum/go-ethereum/consensus"
finalityTracking "github.com/ethereum/go-ethereum/consensus/consortium/generated_contracts/finality_tracking"
"github.com/ethereum/go-ethereum/consensus/consortium/generated_contracts/profile"
roninValidatorSet "github.com/ethereum/go-ethereum/consensus/consortium/generated_contracts/ronin_validator_set"
slashIndicator "github.com/ethereum/go-ethereum/consensus/consortium/generated_contracts/slash_indicator"
Expand Down Expand Up @@ -69,6 +70,7 @@ type ContractIntegrator struct {
roninValidatorSetSC *roninValidatorSet.RoninValidatorSet
slashIndicatorSC *slashIndicator.SlashIndicator
profileSC *profile.Profile
finalityTrackingSC *finalityTracking.FinalityTracking
signTxFn SignerTxFn
coinbase common.Address
}
Expand All @@ -93,11 +95,18 @@ func NewContractIntegrator(config *chainParams.ChainConfig, backend bind.Contrac
return nil, err
}

// Create Finality Tracking contract instance
finalityTrackingSC, err := finalityTracking.NewFinalityTracking(config.ConsortiumV2Contracts.FinalityTracking, backend)
if err != nil {
return nil, err
}

return &ContractIntegrator{
chainId: config.ChainID,
roninValidatorSetSC: roninValidatorSetSC,
slashIndicatorSC: slashIndicatorSC,
profileSC: profileSC,
finalityTrackingSC: finalityTrackingSC,
signTxFn: signTxFn,
signer: types.LatestSignerForChainID(config.ChainID),
coinbase: coinbase,
Expand Down Expand Up @@ -214,8 +223,7 @@ func (c *ContractIntegrator) Slash(opts *ApplyTransactOpts, spoiledValidator com

func (c *ContractIntegrator) FinalityReward(opts *ApplyTransactOpts, votedValidators []common.Address) error {
nonce := opts.State.GetNonce(c.coinbase)
// FIXME: Change this
tx, err := c.slashIndicatorSC.SlashUnavailability(getTransactionOpts(c.coinbase, nonce, c.chainId, c.signTxFn), common.Address{})
tx, err := c.finalityTrackingSC.RecordFinality(getTransactionOpts(c.coinbase, nonce, c.chainId, c.signTxFn), votedValidators)
if err != nil {
return err
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,7 @@ type ConsortiumV2Contracts struct {
RoninValidatorSet common.Address `json:"roninValidatorSet"`
SlashIndicator common.Address `json:"slashIndicator"`
ProfileContract common.Address `json:"profileContract"`
FinalityTracking common.Address `json:"finalityTracking"`
}

func (c *ConsortiumV2Contracts) IsSystemContract(address common.Address) bool {
Expand Down Expand Up @@ -619,11 +620,16 @@ func (c *ChainConfig) String() string {
profileContract = c.ConsortiumV2Contracts.ProfileContract
}

finalityTrackingContract := common.HexToAddress("")
if c.ConsortiumV2Contracts != nil {
finalityTrackingContract = c.ConsortiumV2Contracts.FinalityTracking
}

chainConfigFmt := "{ChainID: %v Homestead: %v DAO: %v DAOSupport: %v EIP150: %v EIP155: %v EIP158: %v Byzantium: %v Constantinople: %v "
chainConfigFmt += "Petersburg: %v Istanbul: %v, Odysseus: %v, Fenix: %v, Muir Glacier: %v, Berlin: %v, London: %v, Arrow Glacier: %v, "
chainConfigFmt += "Engine: %v, Blacklist Contract: %v, Fenix Validator Contract: %v, ConsortiumV2: %v, ConsortiumV2.RoninValidatorSet: %v, "
chainConfigFmt += "ConsortiumV2.SlashIndicator: %v, ConsortiumV2.StakingContract: %v, Puffy: %v, Buba: %v, Olek: %v, Shillin: %v, "
chainConfigFmt += "ConsortiumV2.ProfileContract: %v}"
chainConfigFmt += "ConsortiumV2.ProfileContract: %v, ConsortiumV2.FinalityTracking: %v}"

return fmt.Sprintf(chainConfigFmt,
c.ChainID,
Expand Down Expand Up @@ -655,6 +661,7 @@ func (c *ChainConfig) String() string {
c.OlekBlock,
c.ShillinBlock,
profileContract.Hex(),
finalityTrackingContract.Hex(),
)
}

Expand Down

0 comments on commit d3cfddf

Please sign in to comment.