github.com/mavryk-network/mvgo@v1.19.9/mavryk/protocols.go (about)

     1  // Copyright (c) 2020-2023 Blockwatch Data Inc.
     2  // Author: alex@blockwatch.cc
     3  
     4  package mavryk
     5  
     6  import "sync"
     7  
     8  var (
     9  	ProtoAlpha     = MustParseProtocolHash("ProtoALphaALphaALphaALphaALphaALphaALphaALphaDdp3zK")
    10  	ProtoGenesis   = MustParseProtocolHash("PrihK96nBAFSxVL1GLJTVhu9YnzkMFiBeuJRPA8NwuZVZCE1L6i")
    11  	ProtoBootstrap = MustParseProtocolHash("Ps9mPmXaRzmzk35gbAYNCAw6UXdE2qoABTHbN2oEEc1qM7CwT9P")
    12  	ProtoV001      = MustParseProtocolHash("PtAtLasomUEW99aVhVTrqjCHjJSpFUa8uHNEAEamx9v2SNeTaNp")
    13  	ProtoV002      = MustParseProtocolHash("Pt8h9rz3r9F3Yx3wzJqF42sxsyVoo6kL4FBoJSWRzKmDvjXjHwV")
    14  
    15  	// aliases
    16  	PtAtLas  = ProtoV001
    17  	PtBoreas = ProtoV002
    18  
    19  	Mainnet   = MustParseChainIdHash("NetXdQprcVkpaWU")
    20  	Basenet   = MustParseChainIdHash("NetXnHfVqm9iesp")
    21  	Atlasnet  = MustParseChainIdHash("NetXvyTAafh8goH")
    22  	Boreasnet = MustParseChainIdHash("NetXvyTAafh8goH")
    23  
    24  	versionsMtx = sync.RWMutex{}
    25  	Versions    = map[ProtocolHash]int{
    26  		ProtoGenesis:   0,
    27  		ProtoBootstrap: 0,
    28  		ProtoV001:      18,
    29  		ProtoV002:      19,
    30  		ProtoAlpha:     19,
    31  	}
    32  
    33  	Deployments = map[ChainIdHash]ProtocolHistory{
    34  		Mainnet: {
    35  			{ProtoGenesis, 0, 0, 0, 0, 5, 4096, 256},   // 0
    36  			{ProtoBootstrap, 0, 1, 1, 0, 5, 4096, 256}, // 0
    37  			// {PtAtLas, 2, 2, 28082, 0, 5, 4096, 256},    // v18
    38  			{PtAtLas, 0, 5070849, 5726208, 703, 5, 16384, 1024}, // v18
    39  			{PtBoreas, 0, 5726209, -1, 743, 2, 24576, 24576},    // v19
    40  		},
    41  		Basenet: {
    42  			{ProtoGenesis, 0, 0, 0, 0, 3, 4096, 256},          // 0
    43  			{ProtoBootstrap, 0, 1, 1, 0, 3, 4096, 256},        // 0
    44  			{PtAtLas, 0, 5316609, 6422528, 913, 3, 8192, 512}, // v18
    45  			{PtBoreas, 0, 6422529, -1, 1048, 2, 12288, 12288}, // v19
    46  		},
    47  		Atlasnet: {
    48  			{ProtoGenesis, 0, 0, 0, 0, 3, 4096, 256},   // 0
    49  			{ProtoBootstrap, 0, 1, 1, 0, 3, 8192, 512}, // 0
    50  			{PtAtLas, 0, 16385, -1, 2, 3, 8192, 512},   // v18
    51  		},
    52  		Boreasnet: {
    53  			{ProtoGenesis, 0, 0, 0, 0, 3, 8192, 512},    // 0
    54  			{ProtoBootstrap, 0, 1, 1, 0, 3, 8192, 512},  // 0
    55  			{PtAtLas, 2, 2, 8192, 0, 3, 8192, 512},      // v18
    56  			{PtBoreas, 0, 8193, -1, 1, 2, 12288, 12288}, // v19
    57  		},
    58  	}
    59  )
    60  
    61  type Deployment struct {
    62  	Protocol             ProtocolHash
    63  	StartOffset          int64
    64  	StartHeight          int64
    65  	EndHeight            int64
    66  	StartCycle           int64
    67  	ConsensusRightsDelay int64
    68  	BlocksPerCycle       int64
    69  	BlocksPerSnapshot    int64
    70  }
    71  
    72  type ProtocolHistory []Deployment
    73  
    74  func (h ProtocolHistory) Clone() ProtocolHistory {
    75  	clone := make(ProtocolHistory, len(h))
    76  	copy(clone, h)
    77  	return clone
    78  }
    79  
    80  func (h ProtocolHistory) AtBlock(height int64) (d Deployment) {
    81  	d = h.Last()
    82  	for i := len(h) - 1; i >= 0; i-- {
    83  		if h[i].StartHeight <= height {
    84  			d = h[i]
    85  			break
    86  		}
    87  	}
    88  	return
    89  }
    90  
    91  func (h ProtocolHistory) AtCycle(cycle int64) (d Deployment) {
    92  	d = h.Last()
    93  	for i := len(h) - 1; i >= 0; i-- {
    94  		if h[i].StartCycle <= cycle {
    95  			d = h[i]
    96  			break
    97  		}
    98  	}
    99  	return
   100  }
   101  
   102  func (h ProtocolHistory) AtProtocol(proto ProtocolHash) (d Deployment) {
   103  	d = h.Last()
   104  	for _, v := range h {
   105  		if v.Protocol == proto {
   106  			d = v
   107  			break
   108  		}
   109  	}
   110  	return
   111  }
   112  
   113  func (h *ProtocolHistory) Add(d Deployment) {
   114  	(*h) = append((*h), d)
   115  }
   116  
   117  func (h ProtocolHistory) Last() (d Deployment) {
   118  	if l := len(h); l > 0 {
   119  		d = h[l-1]
   120  	}
   121  	return
   122  }