code.vegaprotocol.io/vega@v0.79.0/datanode/service/protocol_upgrade.go (about) 1 // Copyright (C) 2023 Gobalsky Labs Limited 2 // 3 // This program is free software: you can redistribute it and/or modify 4 // it under the terms of the GNU Affero General Public License as 5 // published by the Free Software Foundation, either version 3 of the 6 // License, or (at your option) any later version. 7 // 8 // This program is distributed in the hope that it will be useful, 9 // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 // GNU Affero General Public License for more details. 12 // 13 // You should have received a copy of the GNU Affero General Public License 14 // along with this program. If not, see <http://www.gnu.org/licenses/>. 15 16 package service 17 18 import ( 19 "context" 20 "sync/atomic" 21 22 "code.vegaprotocol.io/vega/datanode/entities" 23 "code.vegaprotocol.io/vega/logging" 24 ) 25 26 type pupStore interface { 27 Add(ctx context.Context, p entities.ProtocolUpgradeProposal) error 28 List(ctx context.Context, 29 status *entities.ProtocolUpgradeProposalStatus, 30 approvedBy *string, 31 pagination entities.CursorPagination, 32 ) ([]entities.ProtocolUpgradeProposal, entities.PageInfo, error) 33 GetByTxHash(ctx context.Context, txHash entities.TxHash) ([]entities.ProtocolUpgradeProposal, error) 34 } 35 type ProtocolUpgrade struct { 36 pupStore pupStore 37 38 // Flag update needs to be visible across threads 39 upgradeStarted atomic.Bool 40 log *logging.Logger 41 } 42 43 func NewProtocolUpgrade(pupStore pupStore, log *logging.Logger) *ProtocolUpgrade { 44 return &ProtocolUpgrade{ 45 pupStore: pupStore, 46 log: log, 47 } 48 } 49 50 func (p *ProtocolUpgrade) GetProtocolUpgradeStarted() bool { 51 return p.upgradeStarted.Load() 52 } 53 54 func (p *ProtocolUpgrade) SetProtocolUpgradeStarted() { 55 p.log.Info("datanode is ready for protocol upgrade") 56 p.upgradeStarted.Store(true) 57 } 58 59 func (p *ProtocolUpgrade) AddProposal(ctx context.Context, pup entities.ProtocolUpgradeProposal) error { 60 return p.pupStore.Add(ctx, pup) 61 } 62 63 func (p *ProtocolUpgrade) ListProposals(ctx context.Context, 64 status *entities.ProtocolUpgradeProposalStatus, 65 approvedBy *string, 66 pagination entities.CursorPagination, 67 ) ([]entities.ProtocolUpgradeProposal, entities.PageInfo, error) { 68 return p.pupStore.List(ctx, status, approvedBy, pagination) 69 } 70 71 func (p *ProtocolUpgrade) GetByTxHash(ctx context.Context, txHash entities.TxHash) ([]entities.ProtocolUpgradeProposal, error) { 72 return p.pupStore.GetByTxHash(ctx, txHash) 73 }