backend.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // Copyright 2017 The go-ethereum Authors
  2. // This file is part of the go-ethereum library.
  3. //
  4. // The go-ethereum library is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU Lesser General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // The go-ethereum library is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU Lesser General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU Lesser General Public License
  15. // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
  16. package istanbul
  17. import (
  18. "math/big"
  19. "time"
  20. "github.com/ethereum/go-ethereum/common"
  21. "github.com/ethereum/go-ethereum/event"
  22. )
  23. // Backend provides application specific functions for Istanbul core
  24. type Backend interface {
  25. // Address returns the owner's address
  26. Address() common.Address
  27. // Validators returns the validator set
  28. Validators(proposal Proposal) ValidatorSet
  29. // EventMux returns the event mux in backend
  30. EventMux() *event.TypeMux
  31. // Broadcast sends a message to all validators (include self)
  32. Broadcast(valSet ValidatorSet, code uint64, payload []byte) error
  33. // Gossip sends a message to all validators (exclude self)
  34. Gossip(valSet ValidatorSet, code uint64, payload []byte) error
  35. // Commit delivers an approved proposal to backend.
  36. // The delivered proposal will be put into blockchain.
  37. Commit(proposal Proposal, seals [][]byte, round *big.Int) error
  38. // Verify verifies the proposal. If a consensus.ErrFutureBlock error is returned,
  39. // the time difference of the proposal and current time is also returned.
  40. Verify(Proposal) (time.Duration, error)
  41. // Sign signs input data with the backend's private key
  42. Sign([]byte) ([]byte, error)
  43. // SignWithoutHashing sign input data with the backend's private key without hashing the input data
  44. SignWithoutHashing([]byte) ([]byte, error)
  45. // CheckSignature verifies the signature by checking if it's signed by
  46. // the given validator
  47. CheckSignature(data []byte, addr common.Address, sig []byte) error
  48. // LastProposal retrieves latest committed proposal and the address of proposer
  49. LastProposal() (Proposal, common.Address)
  50. // HasPropsal checks if the combination of the given hash and height matches any existing blocks
  51. HasPropsal(hash common.Hash, number *big.Int) bool
  52. // GetProposer returns the proposer of the given block height
  53. GetProposer(number uint64) common.Address
  54. // ParentValidators returns the validator set of the given proposal's parent block
  55. ParentValidators(proposal Proposal) ValidatorSet
  56. // HasBadProposal returns whether the block with the hash is a bad block
  57. HasBadProposal(hash common.Hash) bool
  58. Close() error
  59. // IsQBFTConsensus checks qbftBlock fork block and returns if it should be enabled
  60. IsQBFTConsensusAt(*big.Int) bool
  61. // StartQBFTConsensus stops existing legacy ibft consensus and starts the new qbft consensus
  62. StartQBFTConsensus() error
  63. }