ValidateAndSignBlock validates the given block against the current blockchain and, if valid, computes and returns a signature for the block. It is used as the httpjson handler for /rpc/signer/sign-block.
(ctx context.Context, b *legacy.Block)
| 78 | // and, if valid, computes and returns a signature for the block. It |
| 79 | // is used as the httpjson handler for /rpc/signer/sign-block. |
| 80 | func (s *BlockSigner) ValidateAndSignBlock(ctx context.Context, b *legacy.Block) ([]byte, error) { |
| 81 | err := <-s.c.BlockSoonWaiter(ctx, b.Height-1) |
| 82 | if err != nil { |
| 83 | return nil, errors.Wrapf(err, "waiting for block at height %d", b.Height-1) |
| 84 | } |
| 85 | prev, err := s.c.GetBlock(ctx, b.Height-1) |
| 86 | if err != nil { |
| 87 | return nil, errors.Wrap(err, "getting block at height %d", b.Height-1) |
| 88 | } |
| 89 | // TODO: Add the ability to change the consensus program |
| 90 | // by having a current consensus program, and a potential |
| 91 | // next consensus program. Once the next consensus program |
| 92 | // has been used, it will become the current consensus program |
| 93 | // and the only signable consensus program until a new |
| 94 | // next is set. |
| 95 | if !bytes.Equal(b.ConsensusProgram, prev.ConsensusProgram) { |
| 96 | return nil, errors.Wrap(ErrConsensusChange) |
| 97 | } |
| 98 | err = s.c.ValidateBlockForSig(ctx, b) |
| 99 | if err != nil { |
| 100 | return nil, errors.Wrap(err, "validating block for signature") |
| 101 | } |
| 102 | |
| 103 | err = lockBlockHeight(ctx, s.db, b) |
| 104 | if err != nil { |
| 105 | return nil, errors.Wrap(err, "lock block height") |
| 106 | } |
| 107 | |
| 108 | sig, err := s.hsm.Sign(ctx, s.Pub, &b.BlockHeader) |
| 109 | if err != nil { |
| 110 | return nil, errors.Sub(ErrInvalidKey, err) |
| 111 | } |
| 112 | return sig, nil |
| 113 | } |
| 114 | |
| 115 | // lockBlockHeight records a signer's intention to sign a given block |
| 116 | // at a given height. It's an error if a different block at the same |
nothing calls this directly
no test coverage detected