Skip to content

Commit

Permalink
Merge pull request #98 from bttcprotocol/release_1.0.9
Browse files Browse the repository at this point in the history
Release 1.0.9
  • Loading branch information
bladehan1 authored Nov 27, 2024
2 parents 36f89fe + 1886d53 commit 4b73132
Show file tree
Hide file tree
Showing 9 changed files with 124 additions and 13 deletions.
15 changes: 15 additions & 0 deletions checkpoint/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import (
"strconv"
"time"

featuremanagerTypes "github.com/maticnetwork/heimdall/featuremanager/types"
"github.com/maticnetwork/heimdall/featuremanager/util"

sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/maticnetwork/heimdall/checkpoint/types"
Expand Down Expand Up @@ -233,6 +236,18 @@ func handleMsgCheckpointNoAck(ctx sdk.Context, msg types.MsgCheckpointNoAck, k K
return common.ErrInvalidNoACK(k.Codespace()).Result()
}

//Hardfork to check the validaty of the NoAckProposer
targetFeature := util.GetFeatureConfig().GetFeature(ctx, featuremanagerTypes.NoAckValidatorCheck)
if targetFeature.IsOpen {
logger.Debug("NoAckValidatorCheck is open")
currentValidatorSet := k.sk.GetValidatorSet(ctx)
//If NoAck sender is not the valid proposer, return error
if !currentValidatorSet.HasAddress(msg.From.Bytes()) {
logger.Debug("Invalid No ACK -- Invalid No ACK Proposer")
return common.ErrInvalidNoACKProposer(k.Codespace()).Result()
}
}

// Check last no ack - prevents repetitive no-ack
lastNoAck := k.GetLastNoAck(ctx)
lastNoAckTime := time.Unix(int64(lastNoAck), 0)
Expand Down
9 changes: 7 additions & 2 deletions cmd/deliverycli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,12 @@ func main() {

// chain id
rootCmd.PersistentFlags().String(client.FlagChainID, "", "Chain ID of tendermint node")

rootCmd.PersistentFlags().String(
helper.WithDeliveryConfigFlag,
"",
"Override of delivery config file (default <home>/.deliveryd/config/delivery-config.toml)",
)

// add query/post commands (custom to binary)
rootCmd.AddCommand(
rpc.StatusCommand(),
Expand All @@ -112,7 +117,7 @@ func main() {
)

// bind with-heimdall-config config with root cmd
if err := viper.BindPFlag(helper.WithDeliveryConfigFlag, rootCmd.Flags().Lookup(helper.WithDeliveryConfigFlag)); err != nil {
if err := viper.BindPFlag(helper.WithDeliveryConfigFlag, rootCmd.PersistentFlags().Lookup(helper.WithDeliveryConfigFlag)); err != nil {
logger.Error("main | BindPFlag | helper.WithDeliveryConfigFlag", "Error", err)
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/deliveryd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func main() {
)

// bind with-heimdall-config config with root cmd
if err := viper.BindPFlag(helper.WithDeliveryConfigFlag, rootCmd.Flags().Lookup(helper.WithDeliveryConfigFlag)); err != nil {
if err := viper.BindPFlag(helper.WithDeliveryConfigFlag, rootCmd.PersistentFlags().Lookup(helper.WithDeliveryConfigFlag)); err != nil {
logger.Error("main | BindPFlag | helper.WithDeliveryConfigFlag", "Error", err)
}

Expand Down
4 changes: 4 additions & 0 deletions common/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@ func ErrInvalidNoACK(codespace sdk.CodespaceType) sdk.Error {
return newError(codespace, CodeInvalidNoACK, "Invalid No ACK -- Waiting for last checkpoint ACK")
}

func ErrInvalidNoACKProposer(codespace sdk.CodespaceType) sdk.Error {
return newError(codespace, CodeInvalidNoACK, "Invalid No ACK Proposer")
}

func ErrTooManyNoACK(codespace sdk.CodespaceType) sdk.Error {
return newError(codespace, CodeTooManyNoAck, "Too many no-acks")
}
Expand Down
1 change: 1 addition & 0 deletions featuremanager/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ func (k Keeper) RegisterFeature() {
k.addFeature(types.DynamicCheckpoint)
k.addFeature(types.SupportMapMarshaling)
k.addFeature(types.FinalizedEth)
k.addFeature(types.NoAckValidatorCheck)
}

func (k Keeper) HasFeature(feature string) bool {
Expand Down
1 change: 1 addition & 0 deletions featuremanager/types/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ const (
SupportMapMarshaling = "SupportMapMarshaling"
DynamicCheckpoint = "DynamicCheckpoint"
FinalizedEth = "FinalizedEth"
NoAckValidatorCheck = "NoAckValidatorCheck"
)
4 changes: 4 additions & 0 deletions helper/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"strings"
"time"

"github.com/maticnetwork/heimdall/helper/fork"

"github.com/maticnetwork/heimdall/tron"

ethCrypto "github.com/ethereum/go-ethereum/crypto"
Expand Down Expand Up @@ -279,6 +281,8 @@ func InitDeliveryConfigWith(homeDir string, deliveryConfigFilePath string) {
privVal := privval.LoadFilePV(filepath.Join(configDir, "priv_validator_key.json"), filepath.Join(configDir, "priv_validator_key.json"))
cdc.MustUnmarshalBinaryBare(privVal.Key.PrivKey.Bytes(), &privObject)
cdc.MustUnmarshalBinaryBare(privObject.PubKey().Bytes(), &pubObject)

fork.UpdateForkConfig(GenesisDoc.ChainID)
}

// GetDefaultHeimdallConfig returns configration with default params
Expand Down
73 changes: 73 additions & 0 deletions helper/fork/fork.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package fork

import (
"log"

"github.com/ethereum/go-ethereum/common/hexutil"
)

const (
MainChainID = "delivery-199"
DonauChainID = "delivery-1029"
InnerChainID = ":delivery-22125"
//nolint:lll
donauMultiChain = "0x7b22636861696e5f706172616d657465725f6d6170223a7b22657468223a7b2274785f636f6e6669726d6174696f6e73223a223634222c2261637469766174655f686569676874223a2230222c227374616b696e675f6d616e616765725f61646472657373223a22307866653331646132376262613964613638643564653633373464323538353566393935396138353238222c22736c6173685f6d616e616765725f61646472657373223a22307830303030303030303030303030303030303030303030303030303030303030303030303030303030222c22726f6f745f636861696e5f61646472657373223a22307832663661323032616437633638373362336362643166333937653939623262306262313438613837222c227374616b696e675f696e666f5f61646472657373223a22307834393963623131363637633031323834316161366432343166376533303032336336363366353435222c2273746174655f73656e6465725f61646472657373223a22307833356235336637653161623064373662636333633261666331656336373839313233343262336137227d2c22627363223a7b2274785f636f6e6669726d6174696f6e73223a223134222c2261637469766174655f686569676874223a22313030222c227374616b696e675f6d616e616765725f61646472657373223a22307862643034313530393434356366616561626566323261623462623332343930393138653561613533222c22736c6173685f6d616e616765725f61646472657373223a22307830303030303030303030303030303030303030303030303030303030303030303030303030303030222c22726f6f745f636861696e5f61646472657373223a22307865323331396562663066373831326466633064363533623532323566323161393362613139313937222c227374616b696e675f696e666f5f61646472657373223a22307830353537643166313261616336643230383733646639636336356434613066303631613738653536222c2273746174655f73656e6465725f61646472657373223a22307831303335653262336564306236323438346164393932626139383331643830313538326663343238227d7d7d"
//nolint:lll
innerMultiChain = "0x7b22636861696e5f706172616d657465725f6d6170223a7b22657468223a7b2274785f636f6e6669726d6174696f6e73223a223634222c2261637469766174655f686569676874223a2230222c227374616b696e675f6d616e616765725f61646472657373223a22307861353435333262626566333366366462643837353163303930663031323739666361633434633764222c22736c6173685f6d616e616765725f61646472657373223a22307830303030303030303030303030303030303030303030303030303030303030303030303030303030222c22726f6f745f636861696e5f61646472657373223a22307861326132333231616561623461626662396630656636353939626636333632376239656165333661222c227374616b696e675f696e666f5f61646472657373223a22307832376235633330313739633336656339613736393366626465383062656363356435636230333566222c2273746174655f73656e6465725f61646472657373223a22307839623036393962313431643739303630383535396637356231383037633066306635303030666631227d2c22627363223a7b2274785f636f6e6669726d6174696f6e73223a223136222c2261637469766174655f686569676874223a22313030222c227374616b696e675f6d616e616765725f61646472657373223a22307835323865633566626331333739656535383364306139623362373631316439383233313663323661222c22736c6173685f6d616e616765725f61646472657373223a22307830303030303030303030303030303030303030303030303030303030303030303030303030303030222c22726f6f745f636861696e5f61646472657373223a22307863353262386565623364353338353233626663613730383339616339366166303435613930333031222c227374616b696e675f696e666f5f61646472657373223a22307861326132333231616561623461626662396630656636353939626636333632376239656165333661222c2273746174655f73656e6465725f61646472657373223a22307839363132373366313335663966326635643330393362626537376362313662393266636461656133227d7d7d"
)

// newMarshalForkHeight json marshal height.
var newMarshalForkHeight int64

// multiChainForkHeight multiChain.
var multiChainForkHeight int64

// multiChainForkVal fork value.
var multiChainForkVal = []byte{}

func GetNewMarshalForkHeight() int64 {
return newMarshalForkHeight
}

func GetMultiChainForkHeight() int64 {
return multiChainForkHeight
}

func GetMultiChainForkVal() []byte {
return multiChainForkVal
}

func UpdateForkConfig(chainID string) {
var err error

switch chainID {
case MainChainID:
// multiChain proposal:5 voting_end_time:2023-07-11T07:44:13.
newMarshalForkHeight = 8604000
// 0:no need to fork.
multiChainForkHeight = 0
multiChainForkVal = []byte{}
case DonauChainID:
// multiChain proposal:14.
multiChainForkHeight = 12836457
newMarshalForkHeight = multiChainForkHeight + 1

multiChainForkVal, err = hexutil.Decode(donauMultiChain)
if err != nil {
log.Fatalln("decode donau multiChain value err", err)
}
case InnerChainID:
// multiChain proposal:42.
multiChainForkHeight = 11853136
newMarshalForkHeight = multiChainForkHeight + 1

multiChainForkVal, err = hexutil.Decode(innerMultiChain)
if err != nil {
log.Fatalln("decode test multiChain value err", err)
}
default:
newMarshalForkHeight = 0
multiChainForkHeight = 0
multiChainForkVal = []byte{}
}
}
28 changes: 18 additions & 10 deletions params/subspace/subspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ package subspace

import (
"encoding/json"
"github.com/ethereum/go-ethereum/log"
"reflect"

"github.com/maticnetwork/heimdall/helper/fork"

"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"

Expand All @@ -21,10 +24,6 @@ const (
ParamsWithMultiChains string = "ParamsWithMultiChains"
FeatureParams string = "FeatureParams"
SupportFeature string = "SupportFeature"

MainChain string = "delivery-199"
DonaoChain string = "delivery-1029"
InnerChain string = ":delivery-22125"
)

// hasMap is used for marshalling and unmarshaling for map.
Expand All @@ -42,12 +41,8 @@ func hasMap(ctx sdk.Context, s Subspace, key string) bool {
// fix above issues.

switch ctx.ChainID() {
case MainChain, DonaoChain, InnerChain:
store := s.kvStore(ctx)

if bz := store.Get([]byte(SupportFeature)); bz == nil {
return false
}
case fork.MainChainID, fork.DonauChainID, fork.InnerChainID:
return s.isMultiParamsSupportNewMarshal(ctx)
}

fallthrough
Expand Down Expand Up @@ -203,6 +198,13 @@ func (s Subspace) checkType(store sdk.KVStore, key []byte, param interface{}) {
}
}

func (s Subspace) isMultiParamsSupportNewMarshal(ctx sdk.Context) bool {
if ctx.BlockHeight() < fork.GetNewMarshalForkHeight() {
return false
}
return true
}

// Set stores the parameter. It returns error if stored parameter has different type from input.
// It also set to the transient store to record change.
func (s Subspace) Set(ctx sdk.Context, key []byte, param interface{}) {
Expand All @@ -218,6 +220,12 @@ func (s Subspace) Set(ctx sdk.Context, key []byte, param interface{}) {
data, err = json.Marshal(param)
} else {
data, err = s.cdc.MarshalJSON(param)
//set multiChain fork val
forkHeight := fork.GetMultiChainForkHeight()
if string(key) == ParamsWithMultiChains && forkHeight != 0 && forkHeight == ctx.BlockHeight() {
log.Info("set ParamsWithMultiChains in", "height", forkHeight)
data = fork.GetMultiChainForkVal()
}
}

if err != nil {
Expand Down

0 comments on commit 4b73132

Please sign in to comment.