diff --git a/CHANGELOG.md b/CHANGELOG.md index 4715724..58899e8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## v1.19.2 +* Update Parisnet hash +* Update protocol history of ghostnet + +## v1.19.1 +* Update Paris protocol to [ParisB2](https://research-development.nomadic-labs.com/parisB2-announcement.html) + ## v1.19.0 * BREAKING CHANGE: The cannonical import part has been changed from `blockwatch.cc` to `github.com/trilitech` diff --git a/examples/contract/main.go b/examples/contract/main.go index 48f52c1..2b61d98 100644 --- a/examples/contract/main.go +++ b/examples/contract/main.go @@ -436,7 +436,7 @@ func balance_of(ctx context.Context, c *rpc.Client, addr, owner, id string) erro return err } req := []contract.FA2BalanceRequest{ - contract.FA2BalanceRequest{ + { Owner: own, TokenId: tezos.NewZ(i), }, diff --git a/examples/tzgen/FA2NFT.go b/examples/tzgen/FA2NFT.go index 6f3fce6..6e4c266 100644 --- a/examples/tzgen/FA2NFT.go +++ b/examples/tzgen/FA2NFT.go @@ -10,12 +10,12 @@ import ( "math/big" "time" + "github.com/pkg/errors" "github.com/trilitech/tzgo/contract" "github.com/trilitech/tzgo/contract/bind" "github.com/trilitech/tzgo/micheline" "github.com/trilitech/tzgo/rpc" "github.com/trilitech/tzgo/tezos" - "github.com/pkg/errors" ) // Fa2Nft is a generated binding to a Tezos smart contract. diff --git a/examples/tzgen/Hello.go b/examples/tzgen/Hello.go index 2ea416b..b62291b 100644 --- a/examples/tzgen/Hello.go +++ b/examples/tzgen/Hello.go @@ -10,12 +10,12 @@ import ( "math/big" "time" + "github.com/pkg/errors" "github.com/trilitech/tzgo/contract" "github.com/trilitech/tzgo/contract/bind" "github.com/trilitech/tzgo/micheline" "github.com/trilitech/tzgo/rpc" "github.com/trilitech/tzgo/tezos" - "github.com/pkg/errors" ) // Hello is a generated binding to a Tezos smart contract. diff --git a/examples/tzgen/Payable.go b/examples/tzgen/Payable.go index 900325d..cb1ae2f 100644 --- a/examples/tzgen/Payable.go +++ b/examples/tzgen/Payable.go @@ -10,12 +10,12 @@ import ( "math/big" "time" + "github.com/pkg/errors" "github.com/trilitech/tzgo/contract" "github.com/trilitech/tzgo/contract/bind" "github.com/trilitech/tzgo/micheline" "github.com/trilitech/tzgo/rpc" "github.com/trilitech/tzgo/tezos" - "github.com/pkg/errors" ) // Payable is a generated binding to a Tezos smart contract. diff --git a/micheline/primitives.go b/micheline/primitives.go index 13ea367..669327c 100644 --- a/micheline/primitives.go +++ b/micheline/primitives.go @@ -1494,6 +1494,9 @@ func (p *Prim) DecodeBuffer(buf *bytes.Buffer) error { p.Args = append(p.Args, prim) } // annotation array byte size + if buf.Len() < 4 { + return io.ErrShortBuffer + } size = int(binary.BigEndian.Uint32(buf.Next(4))) if buf.Len() < size { return io.ErrShortBuffer diff --git a/rpc/balance.go b/rpc/balance.go index 232d482..4431796 100644 --- a/rpc/balance.go +++ b/rpc/balance.go @@ -34,9 +34,11 @@ type BalanceUpdate struct { // Oxford staking Staker struct { - Contract tezos.Address `json:"contract"` // tz1/2/3 accounts (only stake, unstake) - Delegate tezos.Address `json:"delegate"` // baker - Baker tezos.Address `json:"baker"` // baker + Contract tezos.Address `json:"contract"` // tz1/2/3 accounts (only stake, unstake) + Delegate tezos.Address `json:"delegate"` // baker + Baker tezos.Address `json:"baker"` // baker + BakerOwnStake tezos.Address `json:"baker_own_stake"` // baker: replaced baker in v19 + BakerEdge tezos.Address `json:"baker_edge"` // baker: new in v19 } `json:"staker"` DelayedOp tezos.OpHash `json:"delayed_operation_hash"` } @@ -83,6 +85,10 @@ func (b BalanceUpdate) Address() tezos.Address { return b.Staker.Delegate case b.Staker.Baker.IsValid(): return b.Staker.Baker + case b.Staker.BakerOwnStake.IsValid(): + return b.Staker.BakerOwnStake + case b.Staker.BakerEdge.IsValid(): + return b.Staker.BakerEdge } return tezos.Address{} } diff --git a/rpc/constants.go b/rpc/constants.go index cc6a28f..51b03ff 100644 --- a/rpc/constants.go +++ b/rpc/constants.go @@ -101,6 +101,11 @@ func (c Constants) MapToChainParams() *tezos.Params { MinimalBlockDelay: time.Duration(c.MinimalBlockDelay) * time.Second, } + // Paris blocks per snapshot + if p.BlocksPerSnapshot == 0 { + p.BlocksPerSnapshot = c.BlocksPerCycle + } + // backport preserved cycles if p.ConsensusRightsDelay == 0 { p.ConsensusRightsDelay = c.PreservedCycles diff --git a/rpc/delegates.go b/rpc/delegates.go index 283f5cd..2148f98 100644 --- a/rpc/delegates.go +++ b/rpc/delegates.go @@ -72,7 +72,7 @@ func (c *Client) ListActiveDelegates(ctx context.Context, id BlockID) (DelegateL } selector := "active=true" if p.Version >= 13 { - selector = "with_minimal_stake=true" + selector += "&with_minimal_stake=true" } delegates := make(DelegateList, 0) u := fmt.Sprintf("chains/main/blocks/%s/context/delegates?%s", id, selector) diff --git a/tezos/param_test.go b/tezos/param_test.go index f4ceb30..6658359 100644 --- a/tezos/param_test.go +++ b/tezos/param_test.go @@ -87,10 +87,8 @@ func TestParamsStatic(t *testing.T) { func TestDefaultParams(t *testing.T) { for n, p := range map[string]*tezos.Params{ - "main": tezos.DefaultParams, - "ghost": tezos.GhostnetParams, - "nairobi": tezos.NairobinetParams, - "oxford": tezos.OxfordnetParams, + "main": tezos.DefaultParams, + "ghost": tezos.GhostnetParams, } { if p.Network == "" { t.Errorf("%s params: Empty network name", n) @@ -756,7 +754,7 @@ var paramBlocks = []BlockMetadata{ LevelInfo: &LevelInfo{ Level: 3760128, Cycle: 622, - CyclePosition: 8191, + CyclePosition: 16383, ExpectedCommitment: true, }, VotingPeriodInfo: &VotingPeriodInfo{ @@ -784,7 +782,7 @@ var paramBlocks = []BlockMetadata{ LevelInfo: &LevelInfo{ Level: 5070848, Cycle: 702, - CyclePosition: 8191, + CyclePosition: 16383, ExpectedCommitment: true, }, VotingPeriodInfo: &VotingPeriodInfo{ @@ -812,7 +810,7 @@ var paramBlocks = []BlockMetadata{ LevelInfo: &LevelInfo{ Level: 5726208, Cycle: 742, - CyclePosition: 8191, + CyclePosition: 16383, ExpectedCommitment: true, }, VotingPeriodInfo: &VotingPeriodInfo{ diff --git a/tezos/params.go b/tezos/params.go index 6e8b555..1ecfdd1 100644 --- a/tezos/params.go +++ b/tezos/params.go @@ -40,36 +40,6 @@ var ( WithChainId(Ghostnet). WithDeployment(Deployments[Ghostnet].AtProtocol(ProtoV019)) - // NairobinetParams defines the blockchain configuration for Nairobi testnet. - // To produce compliant transactions, use these defaults in op.WithParams(). - NairobinetParams = (&Params{ - MinimalBlockDelay: 8 * time.Second, - CostPerByte: 250, - OriginationSize: 257, - HardGasLimitPerOperation: 1040000, - HardGasLimitPerBlock: 2600000, - HardStorageLimitPerOperation: 60000, - MaxOperationDataLength: 32768, - MaxOperationsTTL: 240, - }). - WithChainId(Nairobinet). - WithDeployment(Deployments[Nairobinet].AtProtocol(ProtoV017)) - - // OxfordnetParams defines the blockchain configuration for Oxford testnet. - // To produce compliant transactions, use these defaults in op.WithParams(). - OxfordnetParams = (&Params{ - MinimalBlockDelay: 8 * time.Second, - CostPerByte: 250, - OriginationSize: 257, - HardGasLimitPerOperation: 1040000, - HardGasLimitPerBlock: 2600000, - HardStorageLimitPerOperation: 60000, - MaxOperationDataLength: 32768, - MaxOperationsTTL: 240, - }). - WithChainId(Oxfordnet). - WithDeployment(Deployments[Oxfordnet].AtProtocol(ProtoV018)) - // ParisnetParams defines the blockchain configuration for Paris testnet. // To produce compliant transactions, use these defaults in op.WithParams(). ParisnetParams = (&Params{ @@ -141,12 +111,10 @@ func (p *Params) WithChainId(id ChainIdHash) *Params { p.Network = "Mainnet" case Ghostnet: p.Network = "Ghostnet" - case Nairobinet: - p.Network = "Nairobinet" - case Oxfordnet: - p.Network = "Oxfordnet" case Parisnet: p.Network = "Parisnet" + case ParisCnet: + p.Network = "ParisCnet" } } return p @@ -155,7 +123,9 @@ func (p *Params) WithChainId(id ChainIdHash) *Params { func (p *Params) WithProtocol(h ProtocolHash) *Params { var ok bool p.Protocol = h + versionsMtx.RLock() p.Version, ok = Versions[h] + versionsMtx.RUnlock() if !ok { var max int for _, v := range Versions { @@ -165,6 +135,8 @@ func (p *Params) WithProtocol(h ProtocolHash) *Params { max = v } p.Version = max + 1 + versionsMtx.Lock() + defer versionsMtx.Unlock() Versions[h] = p.Version } switch { @@ -265,7 +237,8 @@ func (p *Params) CycleFromHeight(height int64) int64 { func (p *Params) CycleStartHeight(c int64) int64 { // adjust to target cycle at := p.AtCycle(c) - return at.StartHeight - at.StartOffset + (c-at.StartCycle)*at.BlocksPerCycle + res := at.StartHeight - at.StartOffset + (c-at.StartCycle)*at.BlocksPerCycle + return res } func (p *Params) CycleEndHeight(c int64) int64 { @@ -295,6 +268,11 @@ func (p *Params) IsCycleEnd(height int64) bool { } func (p *Params) IsSnapshotBlock(height int64) bool { + // no more snapshots in Paris + if p.Version > 18 && p.IsCycleEnd(height) { + return true + } + // adjust to target height at := p.AtBlock(height) pos := at.CyclePosition(height) + 1 @@ -308,7 +286,11 @@ func (p *Params) SnapshotBlock(cycle int64, index int) int64 { if base < 0 { return 0 } - return at.CycleStartHeight(base) + int64(index+1)*at.BlocksPerSnapshot - 1 + offset := int64(index+1) * at.BlocksPerSnapshot + if offset > at.BlocksPerCycle { + offset = at.BlocksPerCycle + } + return at.CycleStartHeight(base) + offset - 1 } func (p *Params) SnapshotIndex(height int64) int { diff --git a/tezos/protocols.go b/tezos/protocols.go index 1c07f53..5b4e1a4 100644 --- a/tezos/protocols.go +++ b/tezos/protocols.go @@ -3,6 +3,8 @@ package tezos +import "sync" + var ( ProtoAlpha = MustParseProtocolHash("ProtoALphaALphaALphaALphaALphaALphaALphaALphaDdp3zK") ProtoGenesis = MustParseProtocolHash("PrihK96nBAFSxVL1GLJTVhu9YnzkMFiBeuJRPA8NwuZVZCE1L6i") @@ -25,7 +27,8 @@ var ( ProtoV016_2 = MustParseProtocolHash("PtMumbai2TmsJHNGRkD8v8YDbtao7BLUC3wjASn1inAKLFCjaH1") ProtoV017 = MustParseProtocolHash("PtNairobiyssHuh87hEhfVBGCVrK3WnS8Z2FT4ymB5tAa4r1nQf") ProtoV018 = MustParseProtocolHash("ProxfordYmVfjWnRcgjWH36fW6PArwqykTFzotUxRs6gmTcZDuH") - ProtoV019 = MustParseProtocolHash("PtParisBQscdCm6Cfow6ndeU6wKJyA3aV1j4D3gQBQMsTQyJCrz") + ProtoV019 = MustParseProtocolHash("PtParisBxoLz5gzMmn3d9WBQNoPSZakgnkMC2VNuQ3KXfUtUQeZ") + ProtoV020 = MustParseProtocolHash("PsParisCZo7KAh1Z1smVd9ZMZ1HHn5gkzbM94V3PLCpknFWhUAi") // aliases PtAthens = ProtoV004 @@ -44,14 +47,15 @@ var ( PtNairobi = ProtoV017 Proxford = ProtoV018 PtParisB = ProtoV019 + PsParisC = ProtoV020 - Mainnet = MustParseChainIdHash("NetXdQprcVkpaWU") - Ghostnet = MustParseChainIdHash("NetXnHfVqm9iesp") - Nairobinet = MustParseChainIdHash("NetXyuzvDo2Ugzb") - Oxfordnet = MustParseChainIdHash("NetXxWsskGahzQB") - Parisnet = MustParseChainIdHash("NetXo8SqH1c38SS") + Mainnet = MustParseChainIdHash("NetXdQprcVkpaWU") + Ghostnet = MustParseChainIdHash("NetXnHfVqm9iesp") + Parisnet = MustParseChainIdHash("NetXR64bNAYkP4S") + ParisCnet = MustParseChainIdHash("NetXXWAHLEvre9b") - Versions = map[ProtocolHash]int{ + versionsMtx = sync.RWMutex{} + Versions = map[ProtocolHash]int{ ProtoGenesis: 0, ProtoBootstrap: 0, ProtoV001: 1, @@ -73,7 +77,8 @@ var ( ProtoV017: 17, ProtoV018: 18, ProtoV019: 19, - ProtoAlpha: 20, + ProtoV020: 20, + ProtoAlpha: 21, } Deployments = map[ChainIdHash]ProtocolHistory{ @@ -98,38 +103,33 @@ var ( {PtMumbai, 0, 3268609, 3760128, 593, 5, 16384, 1024}, // v16 {PtNairobi, 0, 3760129, 5070848, 623, 5, 16384, 1024}, // v17 {Proxford, 0, 5070849, 5726208, 703, 5, 16384, 1024}, // v18 - {PtParisB, 0, 5726209, -1, 743, 2, 24576, 24576}, // v19 + {PtParisB, 0, 5726209, 5898240, 743, 2, 24576, 24576}, // v19 + {PsParisC, 0, 5898241, -1, 750, 2, 24576, 24576}, // v19 }, Ghostnet: { - {ProtoGenesis, 0, 0, 0, 0, 3, 4096, 256}, // 0 - {ProtoBootstrap, 0, 1, 1, 0, 3, 4096, 256}, // 0 - {PtHangz2, 2, 2, 8191, 0, 3, 4096, 256}, // v11 - {Psithaca, 0, 8192, 765952, 2, 3, 4096, 256}, // v12 - {PtJakart, 0, 765953, 1191936, 187, 3, 4096, 256}, // v13 - {PtKathma, 0, 1191937, 1654784, 291, 3, 4096, 256}, // v14 - {PtLimaPt, 0, 1654785, 2162688, 404, 3, 4096, 256}, // v15 - {PtMumbai, 0, 2162689, 2957312, 528, 3, 8192, 512}, // v16 - {PtNairobi, 0, 2957313, 5316608, 625, 3, 8192, 512}, // v17 - {Proxford, 0, 5316609, -1, 913, 3, 8192, 512}, // v18 - // {PtParisB, 0, 5316609, -1, 913, 3, 8192, 8192}, // v19 + {ProtoGenesis, 0, 0, 0, 0, 3, 4096, 256}, // 0 + {ProtoBootstrap, 0, 1, 1, 0, 3, 4096, 256}, // 0 + {PtHangz2, 2, 2, 8191, 0, 3, 4096, 256}, // v11 + {Psithaca, 0, 8192, 765952, 2, 3, 4096, 256}, // v12 + {PtJakart, 0, 765953, 1191936, 187, 3, 4096, 256}, // v13 + {PtKathma, 0, 1191937, 1654784, 291, 3, 4096, 256}, // v14 + {PtLimaPt, 0, 1654785, 2162688, 404, 3, 4096, 256}, // v15 + {PtMumbai, 0, 2162689, 2957312, 528, 3, 8192, 512}, // v16 + {PtNairobi, 0, 2957313, 5316608, 625, 3, 8192, 512}, // v17 + {Proxford, 0, 5316609, 6422528, 913, 3, 8192, 512}, // v18 + {PtParisB, 0, 6422529, 6729728, 1048, 2, 12288, 12288}, // v19 + {PsParisC, 0, 6729729, -1, 1073, 2, 12288, 12288}, // v19 }, - Nairobinet: { - {ProtoGenesis, 0, 0, 0, 0, 3, 8192, 512}, // 0 - {ProtoBootstrap, 0, 1, 1, 0, 3, 8192, 512}, // 0 - {PtMumbai, 2, 2, 16384, 0, 3, 8192, 512}, // v16 - {PtNairobi, 0, 16385, -1, 2, 3, 8192, 512}, // v17 + Parisnet: { + {ProtoGenesis, 0, 0, 0, 0, 3, 8192, 512}, // 0 + {ProtoBootstrap, 0, 1, 1, 0, 3, 8192, 512}, // 0 + {Proxford, 2, 2, 8192, 0, 3, 8192, 512}, // v18 + {PtParisB, 0, 8193, -1, 1, 2, 12288, 12288}, // v19 }, - Oxfordnet: { + ParisCnet: { {ProtoGenesis, 0, 0, 0, 0, 3, 8192, 512}, // 0 {ProtoBootstrap, 0, 1, 1, 0, 3, 8192, 512}, // 0 - {PtNairobi, 2, 2, 16384, 0, 3, 8192, 512}, // v17 - {Proxford, 0, 16385, -1, 2, 3, 8192, 512}, // v18 - }, - Parisnet: { - {ProtoGenesis, 0, 0, 0, 0, 3, 8192, 512}, // 0 - {ProtoBootstrap, 0, 1, 1, 0, 3, 8192, 512}, // 0 - {Proxford, 2, 2, 16384, 0, 3, 8192, 512}, // v18 - {PtParisB, 0, 16385, -1, 2, 2, 12288, 12288}, // v19 + {PsParisC, 2, 2, -1, 0, 2, 128, 128}, // v19 }, } )