code.vegaprotocol.io/vega@v0.79.0/core/pow/noop_engine.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 pow 17 18 import ( 19 "code.vegaprotocol.io/vega/core/blockchain/abci" 20 "code.vegaprotocol.io/vega/libs/crypto" 21 protoapi "code.vegaprotocol.io/vega/protos/vega/api/v1" 22 23 "github.com/ethereum/go-ethereum/common/math" 24 ) 25 26 type NoopEngine struct { 27 blockHeight uint64 28 blockHash string 29 } 30 31 func NewNoop() *NoopEngine { 32 return &NoopEngine{} 33 } 34 35 func (e *NoopEngine) BeginBlock(blockHeight uint64, blockHash string, txs []abci.Tx) { 36 e.blockHeight = blockHeight 37 e.blockHash = blockHash 38 } 39 40 func (e *NoopEngine) OnFinalize() {} 41 func (e *NoopEngine) EndOfBlock() {} 42 func (e *NoopEngine) Commit() {} 43 func (e *NoopEngine) CheckTx(tx abci.Tx) error { 44 return nil 45 } 46 47 func (e *NoopEngine) ProcessProposal([]abci.Tx) bool { return false } 48 func (e *NoopEngine) CheckBlockTx(tx abci.Tx) (ValidationResult, *uint) { 49 return ValidationResultSuccess, nil 50 } 51 func (e *NoopEngine) EndPrepareProposal([]ValidationEntry) {} 52 func (e *NoopEngine) IsReady() bool { return true } 53 func (e *NoopEngine) SpamPoWNumberOfPastBlocks() uint32 { return uint32(0) } 54 func (e *NoopEngine) SpamPoWDifficulty() uint32 { return uint32(0) } 55 func (e *NoopEngine) SpamPoWHashFunction() string { return "" } 56 func (e *NoopEngine) SpamPoWNumberOfTxPerBlock() uint32 { return uint32(0) } 57 func (e *NoopEngine) SpamPoWIncreasingDifficulty() bool { return false } 58 59 func (e *NoopEngine) BlockData() (uint64, string) { 60 return e.blockHeight, e.blockHash 61 } 62 63 func (e *NoopEngine) GetSpamStatistics(_ string) *protoapi.PoWStatistic { 64 var expected uint64 65 return &protoapi.PoWStatistic{ 66 NumberOfPastBlocks: 500, 67 BlockStates: []*protoapi.PoWBlockState{ 68 { 69 BlockHeight: e.blockHeight, 70 BlockHash: e.blockHash, 71 TransactionsSeen: 0, 72 ExpectedDifficulty: &expected, 73 HashFunction: crypto.Sha3, 74 Difficulty: 0, 75 TxPerBlock: math.MaxUint64, 76 IncreasingDifficulty: true, 77 }, 78 }, 79 } 80 }