github.com/MetalBlockchain/metalgo@v1.11.9/version/constants.go (about)

     1  // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved.
     2  // See the file LICENSE for licensing terms.
     3  
     4  package version
     5  
     6  import (
     7  	"encoding/json"
     8  	"time"
     9  
    10  	_ "embed"
    11  
    12  	"github.com/MetalBlockchain/metalgo/ids"
    13  	"github.com/MetalBlockchain/metalgo/utils/constants"
    14  )
    15  
    16  const (
    17  	Client = "metalgo"
    18  	// RPCChainVMProtocol should be bumped anytime changes are made which
    19  	// require the plugin vm to upgrade to latest avalanchego release to be
    20  	// compatible.
    21  	RPCChainVMProtocol uint = 35
    22  )
    23  
    24  // These are globals that describe network upgrades and node versions
    25  var (
    26  	Current = &Semantic{
    27  		Major: 1,
    28  		Minor: 11,
    29  		Patch: 9,
    30  	}
    31  	CurrentApp = &Application{
    32  		Name:  Client,
    33  		Major: Current.Major,
    34  		Minor: Current.Minor,
    35  		Patch: Current.Patch,
    36  	}
    37  	MinimumCompatibleVersion = &Application{
    38  		Name:  Client,
    39  		Major: 1,
    40  		Minor: 11,
    41  		Patch: 0,
    42  	}
    43  	PrevMinimumCompatibleVersion = &Application{
    44  		Name:  Client,
    45  		Major: 1,
    46  		Minor: 10,
    47  		Patch: 0,
    48  	}
    49  
    50  	CurrentDatabase = DatabaseVersion1_4_5
    51  	PrevDatabase    = DatabaseVersion1_0_0
    52  
    53  	DatabaseVersion1_4_5 = &Semantic{
    54  		Major: 1,
    55  		Minor: 4,
    56  		Patch: 5,
    57  	}
    58  	DatabaseVersion1_0_0 = &Semantic{
    59  		Major: 1,
    60  		Minor: 0,
    61  		Patch: 0,
    62  	}
    63  
    64  	//go:embed compatibility.json
    65  	rpcChainVMProtocolCompatibilityBytes []byte
    66  	// RPCChainVMProtocolCompatibility maps RPCChainVMProtocol versions to the
    67  	// set of metalgo versions that supported that version. This is not used
    68  	// by metalgo, but is useful for downstream libraries.
    69  	RPCChainVMProtocolCompatibility map[uint][]*Semantic
    70  
    71  	DefaultUpgradeTime = time.Date(2020, time.December, 5, 5, 0, 0, 0, time.UTC)
    72  
    73  	ApricotPhase1Times = map[uint32]time.Time{
    74  		constants.MainnetID: time.Date(2020, time.December, 5, 5, 0, 0, 0, time.UTC),
    75  		constants.TahoeID:   time.Date(2020, time.December, 5, 5, 0, 0, 0, time.UTC),
    76  	}
    77  
    78  	ApricotPhase2Times = map[uint32]time.Time{
    79  		constants.MainnetID: time.Date(2020, time.December, 5, 5, 0, 0, 0, time.UTC),
    80  		constants.TahoeID:   time.Date(2020, time.December, 5, 5, 0, 0, 0, time.UTC),
    81  	}
    82  
    83  	ApricotPhase3Times = map[uint32]time.Time{
    84  		constants.MainnetID: time.Date(2020, time.December, 5, 5, 0, 0, 0, time.UTC),
    85  		constants.TahoeID:   time.Date(2020, time.December, 5, 5, 0, 0, 0, time.UTC),
    86  	}
    87  
    88  	ApricotPhase4Times = map[uint32]time.Time{
    89  		constants.MainnetID: time.Date(2020, time.December, 5, 5, 0, 0, 0, time.UTC),
    90  		constants.TahoeID:   time.Date(2020, time.December, 5, 5, 0, 0, 0, time.UTC),
    91  	}
    92  	ApricotPhase4MinPChainHeight = map[uint32]uint64{
    93  		constants.MainnetID: 0,
    94  		constants.TahoeID:   0,
    95  	}
    96  
    97  	ApricotPhase5Times = map[uint32]time.Time{
    98  		constants.MainnetID: time.Date(2020, time.December, 5, 5, 0, 0, 0, time.UTC),
    99  		constants.TahoeID:   time.Date(2020, time.December, 5, 5, 0, 0, 0, time.UTC),
   100  	}
   101  
   102  	ApricotPhasePre6Times = map[uint32]time.Time{
   103  		constants.MainnetID: time.Date(2022, time.September, 8, 20, 0, 0, 0, time.UTC),
   104  		constants.TahoeID:   time.Date(2022, time.September, 8, 20, 0, 0, 0, time.UTC),
   105  	}
   106  
   107  	ApricotPhase6Times = map[uint32]time.Time{
   108  		constants.MainnetID: time.Date(2022, time.September, 8, 22, 0, 0, 0, time.UTC),
   109  		constants.TahoeID:   time.Date(2022, time.September, 8, 22, 0, 0, 0, time.UTC),
   110  	}
   111  
   112  	ApricotPhasePost6Times = map[uint32]time.Time{
   113  		constants.MainnetID: time.Date(2022, time.September, 9, 3, 0, 0, 0, time.UTC),
   114  		constants.TahoeID:   time.Date(2022, time.September, 9, 3, 0, 0, 0, time.UTC),
   115  	}
   116  
   117  	BanffTimes = map[uint32]time.Time{
   118  		constants.MainnetID: time.Date(2022, time.December, 19, 16, 0, 0, 0, time.UTC),
   119  		constants.TahoeID:   time.Date(2022, time.December, 12, 14, 0, 0, 0, time.UTC),
   120  	}
   121  
   122  	CortinaTimes = map[uint32]time.Time{
   123  		constants.MainnetID: time.Date(2023, time.August, 17, 10, 0, 0, 0, time.UTC),
   124  		constants.TahoeID:   time.Date(2023, time.June, 28, 15, 0, 0, 0, time.UTC),
   125  	}
   126  	CortinaXChainStopVertexID = map[uint32]ids.ID{
   127  		// The mainnet stop vertex is well known. It can be verified on any
   128  		// fully synced node by looking at the parentID of the genesis block.
   129  		//
   130  		// Ref: https://subnets.avax.network/x-chain/block/0
   131  		constants.MainnetID: ids.FromStringOrPanic("ewiCzJQVJLYCzeFMcZSe9huX9h7QJPVeMdgDGcTVGTzeNJ3kY"),
   132  		// The fuji stop vertex is well known. It can be verified on any fully
   133  		// synced node by looking at the parentID of the genesis block.
   134  		//
   135  		// Ref: https://subnets-test.avax.network/x-chain/block/0
   136  		constants.TahoeID: ids.FromStringOrPanic("RdWKZYgjgU2NicKHv8mpkR6jgo41W5aNwVhsX5sJgqshDAbQk"),
   137  	}
   138  
   139  	DurangoTimes = map[uint32]time.Time{
   140  		constants.MainnetID: time.Date(2024, time.May, 6, 8, 0, 0, 0, time.UTC),
   141  		constants.TahoeID:   time.Date(2024, time.April, 4, 0, 0, 0, 0, time.UTC),
   142  	}
   143  
   144  	EUpgradeTimes = map[uint32]time.Time{
   145  		constants.MainnetID: time.Date(10000, time.December, 1, 0, 0, 0, 0, time.UTC),
   146  		constants.TahoeID:   time.Date(10000, time.December, 1, 0, 0, 0, 0, time.UTC),
   147  	}
   148  )
   149  
   150  func init() {
   151  	var parsedRPCChainVMCompatibility map[uint][]string
   152  	err := json.Unmarshal(rpcChainVMProtocolCompatibilityBytes, &parsedRPCChainVMCompatibility)
   153  	if err != nil {
   154  		panic(err)
   155  	}
   156  
   157  	RPCChainVMProtocolCompatibility = make(map[uint][]*Semantic)
   158  	for rpcChainVMProtocol, versionStrings := range parsedRPCChainVMCompatibility {
   159  		versions := make([]*Semantic, len(versionStrings))
   160  		for i, versionString := range versionStrings {
   161  			version, err := Parse(versionString)
   162  			if err != nil {
   163  				panic(err)
   164  			}
   165  			versions[i] = version
   166  		}
   167  		RPCChainVMProtocolCompatibility[rpcChainVMProtocol] = versions
   168  	}
   169  }
   170  
   171  func GetApricotPhase1Time(networkID uint32) time.Time {
   172  	if upgradeTime, exists := ApricotPhase1Times[networkID]; exists {
   173  		return upgradeTime
   174  	}
   175  	return DefaultUpgradeTime
   176  }
   177  
   178  func GetApricotPhase2Time(networkID uint32) time.Time {
   179  	if upgradeTime, exists := ApricotPhase2Times[networkID]; exists {
   180  		return upgradeTime
   181  	}
   182  	return DefaultUpgradeTime
   183  }
   184  
   185  func GetApricotPhase3Time(networkID uint32) time.Time {
   186  	if upgradeTime, exists := ApricotPhase3Times[networkID]; exists {
   187  		return upgradeTime
   188  	}
   189  	return DefaultUpgradeTime
   190  }
   191  
   192  func GetApricotPhase4Time(networkID uint32) time.Time {
   193  	if upgradeTime, exists := ApricotPhase4Times[networkID]; exists {
   194  		return upgradeTime
   195  	}
   196  	return DefaultUpgradeTime
   197  }
   198  
   199  func GetApricotPhase5Time(networkID uint32) time.Time {
   200  	if upgradeTime, exists := ApricotPhase5Times[networkID]; exists {
   201  		return upgradeTime
   202  	}
   203  	return DefaultUpgradeTime
   204  }
   205  
   206  func GetApricotPhasePre6Time(networkID uint32) time.Time {
   207  	if upgradeTime, exists := ApricotPhasePre6Times[networkID]; exists {
   208  		return upgradeTime
   209  	}
   210  	return DefaultUpgradeTime
   211  }
   212  
   213  func GetApricotPhase6Time(networkID uint32) time.Time {
   214  	if upgradeTime, exists := ApricotPhase6Times[networkID]; exists {
   215  		return upgradeTime
   216  	}
   217  	return DefaultUpgradeTime
   218  }
   219  
   220  func GetApricotPhasePost6Time(networkID uint32) time.Time {
   221  	if upgradeTime, exists := ApricotPhasePost6Times[networkID]; exists {
   222  		return upgradeTime
   223  	}
   224  	return DefaultUpgradeTime
   225  }
   226  
   227  func GetBanffTime(networkID uint32) time.Time {
   228  	if upgradeTime, exists := BanffTimes[networkID]; exists {
   229  		return upgradeTime
   230  	}
   231  	return DefaultUpgradeTime
   232  }
   233  
   234  func GetCortinaTime(networkID uint32) time.Time {
   235  	if upgradeTime, exists := CortinaTimes[networkID]; exists {
   236  		return upgradeTime
   237  	}
   238  	return DefaultUpgradeTime
   239  }
   240  
   241  func GetDurangoTime(networkID uint32) time.Time {
   242  	if upgradeTime, exists := DurangoTimes[networkID]; exists {
   243  		return upgradeTime
   244  	}
   245  	return DefaultUpgradeTime
   246  }
   247  
   248  func GetEUpgradeTime(networkID uint32) time.Time {
   249  	if upgradeTime, exists := EUpgradeTimes[networkID]; exists {
   250  		return upgradeTime
   251  	}
   252  	return DefaultUpgradeTime
   253  }
   254  
   255  func GetCompatibility(networkID uint32) Compatibility {
   256  	return NewCompatibility(
   257  		CurrentApp,
   258  		MinimumCompatibleVersion,
   259  		GetDurangoTime(networkID),
   260  		PrevMinimumCompatibleVersion,
   261  	)
   262  }