github.com/okex/exchain@v1.8.0/libs/tendermint/types/milestone.go (about)

     1  package types
     2  
     3  import (
     4  	"strconv"
     5  	"sync"
     6  )
     7  
     8  // Disable followings after milestoneMercuryHeight
     9  // 1. TransferToContractBlock
    10  // 2. ChangeEvmDenomByProposal
    11  // 3. BankTransferBlock
    12  // 4. ibc
    13  
    14  var (
    15  	MILESTONE_GENESIS_HEIGHT string
    16  	genesisHeight            int64
    17  
    18  	MILESTONE_MERCURY_HEIGHT string
    19  	milestoneMercuryHeight   int64
    20  
    21  	MILESTONE_VENUS_HEIGHT string
    22  	milestoneVenusHeight   int64
    23  
    24  	MILESTONE_MARS_HEIGHT string
    25  	milestoneMarsHeight   int64
    26  
    27  	MILESTONE_VENUS1_HEIGHT string
    28  	milestoneVenus1Height   int64
    29  
    30  	MILESTONE_VENUS2_HEIGHT string
    31  	milestoneVenus2Height   int64
    32  
    33  	MILESTONE_VENUS3_HEIGHT string
    34  	milestoneVenus3Height   int64
    35  
    36  	MILESTONE_EARTH_HEIGHT string
    37  	milestoneEarthHeight   int64
    38  
    39  	MILESTONE_VENUS4_HEIGHT string
    40  	milestoneVenus4Height   int64
    41  
    42  	MILESTONE_VENUS5_HEIGHT string
    43  	milestoneVenus5Height   int64
    44  
    45  	MILESTONE_VENUS6_NAME       = "venus6"
    46  	milestoneVenus6Height int64 = 0
    47  
    48  	MILESTONE_VENUS7_NAME       = "venus7"
    49  	milestoneVenus7Height int64 = 0
    50  
    51  	// note: it stores the earlies height of the node,and it is used by cli
    52  	nodePruneHeight int64
    53  
    54  	once sync.Once
    55  )
    56  
    57  const (
    58  	MainNet = "exchain-66"
    59  	TestNet = "exchain-65"
    60  )
    61  
    62  const (
    63  	MainNetVeneus1Height = 12988000
    64  	TestNetVeneus1Height = 12067000
    65  
    66  	MainNetVeneusHeight = 8200000
    67  	TestNetVeneusHeight = 8510000
    68  
    69  	MainNetMercuyHeight  = 5150000
    70  	TestNetMercuryHeight = 5300000
    71  
    72  	MainNetGenesisHeight = 2322600
    73  	TestNetGenesisHeight = 1121818
    74  
    75  	TestNetChangeChainId = 2270901
    76  	TestNetChainName1    = "okexchain-65"
    77  )
    78  
    79  func init() {
    80  	once.Do(func() {
    81  		genesisHeight = string2number(MILESTONE_GENESIS_HEIGHT)
    82  		milestoneMercuryHeight = string2number(MILESTONE_MERCURY_HEIGHT)
    83  		milestoneVenusHeight = string2number(MILESTONE_VENUS_HEIGHT)
    84  		milestoneMarsHeight = string2number(MILESTONE_MARS_HEIGHT)
    85  		milestoneVenus1Height = string2number(MILESTONE_VENUS1_HEIGHT)
    86  		milestoneVenus2Height = string2number(MILESTONE_VENUS2_HEIGHT)
    87  		milestoneVenus3Height = string2number(MILESTONE_VENUS3_HEIGHT)
    88  		milestoneEarthHeight = string2number(MILESTONE_EARTH_HEIGHT)
    89  		milestoneVenus4Height = string2number(MILESTONE_VENUS4_HEIGHT)
    90  		milestoneVenus5Height = string2number(MILESTONE_VENUS5_HEIGHT)
    91  	})
    92  }
    93  
    94  func string2number(input string) int64 {
    95  	if len(input) == 0 {
    96  		input = "0"
    97  	}
    98  	res, err := strconv.ParseInt(input, 10, 64)
    99  	if err != nil {
   100  		panic(err)
   101  	}
   102  	return res
   103  }
   104  
   105  func SetupMainNetEnvironment(pruneH int64) {
   106  	milestoneVenusHeight = MainNetVeneusHeight
   107  	milestoneMercuryHeight = MainNetMercuyHeight
   108  	genesisHeight = MainNetGenesisHeight
   109  	nodePruneHeight = pruneH
   110  	milestoneVenus1Height = MainNetVeneus1Height
   111  }
   112  
   113  func SetupTestNetEnvironment(pruneH int64) {
   114  	milestoneVenusHeight = TestNetVeneusHeight
   115  	milestoneMercuryHeight = TestNetMercuryHeight
   116  	genesisHeight = TestNetGenesisHeight
   117  	nodePruneHeight = pruneH
   118  	milestoneVenus1Height = TestNetVeneus1Height
   119  }
   120  
   121  // depracate homstead signer support
   122  func HigherThanMercury(height int64) bool {
   123  	if milestoneMercuryHeight == 0 {
   124  		// milestoneMercuryHeight not enabled
   125  		return false
   126  	}
   127  	return height > milestoneMercuryHeight
   128  }
   129  
   130  func HigherThanVenus(height int64) bool {
   131  	if milestoneVenusHeight == 0 {
   132  		return false
   133  	}
   134  	return height >= milestoneVenusHeight
   135  }
   136  
   137  // use MPT storage model to replace IAVL storage model
   138  func HigherThanMars(height int64) bool {
   139  	if milestoneMarsHeight == 0 {
   140  		return false
   141  	}
   142  	return height > milestoneMarsHeight
   143  }
   144  
   145  // GetMilestoneVenusHeight returns milestoneVenusHeight
   146  func GetMilestoneVenusHeight() int64 {
   147  	return milestoneVenusHeight
   148  }
   149  
   150  // 2322600 is mainnet GenesisHeight
   151  func IsMainNet() bool {
   152  	return MILESTONE_GENESIS_HEIGHT == "2322600"
   153  }
   154  
   155  // 1121818 is testnet GenesisHeight
   156  func IsTestNet() bool {
   157  	return MILESTONE_GENESIS_HEIGHT == "1121818"
   158  }
   159  
   160  func IsPrivateNet() bool {
   161  	return !IsMainNet() && !IsTestNet()
   162  }
   163  
   164  func GetStartBlockHeight() int64 {
   165  	return genesisHeight
   166  }
   167  
   168  func GetNodePruneHeight() int64 {
   169  	return nodePruneHeight
   170  }
   171  
   172  func GetVenusHeight() int64 {
   173  	return milestoneVenusHeight
   174  }
   175  
   176  func GetMercuryHeight() int64 {
   177  	return milestoneMercuryHeight
   178  }
   179  
   180  func GetMarsHeight() int64 {
   181  	return milestoneMarsHeight
   182  }
   183  
   184  // can be used in unit test only
   185  func UnittestOnlySetMilestoneVenusHeight(height int64) {
   186  	milestoneVenusHeight = height
   187  }
   188  
   189  // can be used in unit test only
   190  func UnittestOnlySetMilestoneMarsHeight(height int64) {
   191  	milestoneMarsHeight = height
   192  }
   193  
   194  // ==================================
   195  // =========== Venus1 ===============
   196  func HigherThanVenus1(h int64) bool {
   197  	if milestoneVenus1Height == 0 {
   198  		return false
   199  	}
   200  	return h >= milestoneVenus1Height
   201  }
   202  
   203  func UnittestOnlySetMilestoneVenus1Height(h int64) {
   204  	milestoneVenus1Height = h
   205  }
   206  
   207  func UnittestOnlySetMilestoneVenus6Height(h int64) {
   208  	milestoneVenus6Height = h
   209  }
   210  
   211  func GetVenus1Height() int64 {
   212  	return milestoneVenus1Height
   213  }
   214  
   215  // =========== Venus1 ===============
   216  // ==================================
   217  
   218  // ==================================
   219  // =========== Venus2 ===============
   220  func HigherThanVenus2(h int64) bool {
   221  	if milestoneVenus2Height == 0 {
   222  		return false
   223  	}
   224  	return h >= milestoneVenus2Height
   225  }
   226  
   227  func UnittestOnlySetMilestoneVenus2Height(h int64) {
   228  	milestoneVenus2Height = h
   229  }
   230  
   231  func GetVenus2Height() int64 {
   232  	return milestoneVenus2Height
   233  }
   234  
   235  // =========== Venus2 ===============
   236  // ==================================
   237  
   238  // ==================================
   239  // =========== Venus3 ===============
   240  func HigherThanVenus3(h int64) bool {
   241  	if milestoneVenus3Height == 0 {
   242  		return false
   243  	}
   244  	return h > milestoneVenus3Height
   245  }
   246  
   247  func UnittestOnlySetMilestoneVenus3Height(h int64) {
   248  	milestoneVenus3Height = h
   249  }
   250  
   251  func GetVenus3Height() int64 {
   252  	return milestoneVenus3Height
   253  }
   254  
   255  // =========== Venus3 ===============
   256  // ==================================
   257  
   258  // ==================================
   259  // =========== Earth ===============
   260  func UnittestOnlySetMilestoneEarthHeight(h int64) {
   261  	milestoneEarthHeight = h
   262  }
   263  
   264  func HigherThanEarth(h int64) bool {
   265  	if milestoneEarthHeight == 0 {
   266  		return false
   267  	}
   268  	return h >= milestoneEarthHeight
   269  }
   270  
   271  func GetEarthHeight() int64 {
   272  	return milestoneEarthHeight
   273  }
   274  
   275  // =========== Earth ===============
   276  // ==================================
   277  
   278  // ==================================
   279  // =========== Venus3 ===============
   280  func HigherThanVenus4(h int64) bool {
   281  	if milestoneVenus4Height == 0 {
   282  		return false
   283  	}
   284  	return h > milestoneVenus4Height
   285  }
   286  
   287  func UnittestOnlySetMilestoneVenus4Height(h int64) {
   288  	milestoneVenus4Height = h
   289  }
   290  
   291  func GetVenus4Height() int64 {
   292  	return milestoneVenus4Height
   293  }
   294  
   295  // =========== Venus4 ===============
   296  // ==================================
   297  
   298  // ==================================
   299  // =========== Venus5 ===============
   300  func HigherThanVenus5(h int64) bool {
   301  	if milestoneVenus5Height == 0 {
   302  		return false
   303  	}
   304  	return h > milestoneVenus5Height
   305  }
   306  
   307  func UnittestOnlySetMilestoneVenus5Height(h int64) {
   308  	milestoneVenus5Height = h
   309  }
   310  
   311  func GetVenus5Height() int64 {
   312  	return milestoneVenus5Height
   313  }
   314  
   315  // =========== Venus5 ===============
   316  // ==================================
   317  
   318  // ==================================
   319  // =========== Venus6 ===============
   320  func HigherThanVenus6(h int64) bool {
   321  	if milestoneVenus6Height == 0 {
   322  		return false
   323  	}
   324  	return h > milestoneVenus6Height
   325  }
   326  
   327  func InitMilestoneVenus6Height(h int64) {
   328  	milestoneVenus6Height = h
   329  }
   330  
   331  func GetVenus6Height() int64 {
   332  	return milestoneVenus6Height
   333  }
   334  
   335  // =========== Venus6 ===============
   336  // ==================================
   337  
   338  // ==================================
   339  // =========== Venus7 ===============
   340  func HigherThanVenus7(h int64) bool {
   341  	if milestoneVenus7Height == 0 {
   342  		return false
   343  	}
   344  	return h > milestoneVenus7Height
   345  }
   346  
   347  func InitMilestoneVenus7Height(h int64) {
   348  	milestoneVenus7Height = h
   349  }
   350  
   351  func GetVenus7Height() int64 {
   352  	return milestoneVenus7Height
   353  }
   354  
   355  // =========== Venus7 ===============
   356  // ==================================