code.vegaprotocol.io/vega@v0.79.0/cmd/vega/commands/node/app_wrapper.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 node
    17  
    18  import (
    19  	"context"
    20  
    21  	"github.com/cometbft/cometbft/abci/types"
    22  )
    23  
    24  type appW struct {
    25  	// this is the application currently in use
    26  	impl types.Application
    27  	// this is the application that'll need to be swap if expected by
    28  	// the application, will be call on commit and needs to be swap atomically
    29  	// before returning from Commit
    30  	update types.Application
    31  }
    32  
    33  func newAppW(app types.Application) *appW {
    34  	return &appW{
    35  		impl: app,
    36  	}
    37  }
    38  
    39  func (app *appW) Info(ctx context.Context, req *types.RequestInfo) (*types.ResponseInfo, error) {
    40  	return app.impl.Info(ctx, req)
    41  }
    42  
    43  func (app *appW) CheckTx(ctx context.Context, req *types.RequestCheckTx) (*types.ResponseCheckTx, error) {
    44  	return app.impl.CheckTx(ctx, req)
    45  }
    46  
    47  func (app *appW) Commit(ctx context.Context, req *types.RequestCommit) (*types.ResponseCommit, error) {
    48  	resp, err := app.impl.Commit(ctx, req)
    49  	// if we are scheduled for an upgrade of the protocol
    50  	// let's do it now.
    51  	if app.update != nil {
    52  		app.impl = app.update
    53  		app.update = nil
    54  	}
    55  	return resp, err
    56  }
    57  
    58  func (app *appW) Query(ctx context.Context, req *types.RequestQuery) (*types.ResponseQuery, error) {
    59  	return app.impl.Query(ctx, req)
    60  }
    61  
    62  func (app *appW) InitChain(ctx context.Context, req *types.RequestInitChain) (*types.ResponseInitChain, error) {
    63  	return app.impl.InitChain(ctx, req)
    64  }
    65  
    66  func (app *appW) ListSnapshots(ctx context.Context, req *types.RequestListSnapshots) (*types.ResponseListSnapshots, error) {
    67  	return app.impl.ListSnapshots(ctx, req)
    68  }
    69  
    70  func (app *appW) OfferSnapshot(ctx context.Context, req *types.RequestOfferSnapshot) (*types.ResponseOfferSnapshot, error) {
    71  	return app.impl.OfferSnapshot(ctx, req)
    72  }
    73  
    74  func (app *appW) LoadSnapshotChunk(ctx context.Context, req *types.RequestLoadSnapshotChunk) (*types.ResponseLoadSnapshotChunk, error) {
    75  	return app.impl.LoadSnapshotChunk(ctx, req)
    76  }
    77  
    78  func (app *appW) ApplySnapshotChunk(ctx context.Context, req *types.RequestApplySnapshotChunk) (*types.ResponseApplySnapshotChunk, error) {
    79  	return app.impl.ApplySnapshotChunk(ctx, req)
    80  }
    81  
    82  func (app *appW) PrepareProposal(ctx context.Context, proposal *types.RequestPrepareProposal) (*types.ResponsePrepareProposal, error) {
    83  	return app.impl.PrepareProposal(ctx, proposal)
    84  }
    85  
    86  func (app *appW) ProcessProposal(ctx context.Context, proposal *types.RequestProcessProposal) (*types.ResponseProcessProposal, error) {
    87  	return app.impl.ProcessProposal(ctx, proposal)
    88  }
    89  
    90  func (app *appW) FinalizeBlock(ctx context.Context, req *types.RequestFinalizeBlock) (*types.ResponseFinalizeBlock, error) {
    91  	return app.impl.FinalizeBlock(ctx, req)
    92  }
    93  
    94  func (app *appW) ExtendVote(ctx context.Context, req *types.RequestExtendVote) (*types.ResponseExtendVote, error) {
    95  	return app.impl.ExtendVote(ctx, req)
    96  }
    97  
    98  func (app *appW) VerifyVoteExtension(ctx context.Context, req *types.RequestVerifyVoteExtension) (*types.ResponseVerifyVoteExtension, error) {
    99  	return app.impl.VerifyVoteExtension(ctx, req)
   100  }