From 5501d83408e11ecc38f48fc8d28386c86cd8e03e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tadej=20Jane=C5=BE?= Date: Mon, 8 Jun 2020 13:32:27 +0200 Subject: [PATCH] go/consensus/tendermint/api: Add OwnTxSignerAddress() to app state Add OwnTxSignerAddress() to ApplicationState. --- .changelog/2940.feature.6.md | 3 ++ go/consensus/tendermint/abci/state.go | 43 ++++++++++++++++----------- go/consensus/tendermint/api/state.go | 20 +++++++++---- 3 files changed, 43 insertions(+), 23 deletions(-) create mode 100644 .changelog/2940.feature.6.md diff --git a/.changelog/2940.feature.6.md b/.changelog/2940.feature.6.md new file mode 100644 index 00000000000..79fbc2ecd1c --- /dev/null +++ b/.changelog/2940.feature.6.md @@ -0,0 +1,3 @@ +go/consensus/tendermint/api: Add `OwnTxSignerAddress()` to `ApplicationState` + +It returns the transaction signer's staking address of the local node. diff --git a/go/consensus/tendermint/abci/state.go b/go/consensus/tendermint/abci/state.go index 05daae7a954..1317a3de9fb 100644 --- a/go/consensus/tendermint/abci/state.go +++ b/go/consensus/tendermint/abci/state.go @@ -22,6 +22,7 @@ import ( "github.com/oasisprotocol/oasis-core/go/consensus/tendermint/api" epochtime "github.com/oasisprotocol/oasis-core/go/epochtime/api" genesis "github.com/oasisprotocol/oasis-core/go/genesis/api" + staking "github.com/oasisprotocol/oasis-core/go/staking/api" storage "github.com/oasisprotocol/oasis-core/go/storage/api" storageDB "github.com/oasisprotocol/oasis-core/go/storage/database" "github.com/oasisprotocol/oasis-core/go/storage/mkvs" @@ -59,9 +60,10 @@ type applicationState struct { // nolint: maligned haltMode bool haltEpochHeight epochtime.EpochTime - minGasPrice quantity.Quantity - ownTxSigner signature.PublicKey - disableCheckTx bool + minGasPrice quantity.Quantity + ownTxSigner signature.PublicKey + ownTxSignerAddress staking.Address + disableCheckTx bool metricsClosedCh chan struct{} } @@ -202,6 +204,10 @@ func (s *applicationState) OwnTxSigner() signature.PublicKey { return s.ownTxSigner } +func (s *applicationState) OwnTxSignerAddress() staking.Address { + return s.ownTxSignerAddress +} + func (s *applicationState) inHaltEpoch(ctx *api.Context) bool { blockHeight := s.BlockHeight() @@ -468,21 +474,22 @@ func newApplicationState(ctx context.Context, cfg *ApplicationConfig) (*applicat ctx, cancelCtx := context.WithCancel(ctx) s := &applicationState{ - logger: logging.GetLogger("abci-mux/state"), - ctx: ctx, - cancelCtx: cancelCtx, - deliverTxTree: deliverTxTree, - checkTxTree: checkTxTree, - stateRoot: *stateRoot, - storage: ldb, - statePruner: statePruner, - prunerClosedCh: make(chan struct{}), - prunerNotifyCh: channels.NewRingChannel(1), - haltEpochHeight: cfg.HaltEpochHeight, - minGasPrice: minGasPrice, - ownTxSigner: cfg.OwnTxSigner, - disableCheckTx: cfg.DisableCheckTx, - metricsClosedCh: make(chan struct{}), + logger: logging.GetLogger("abci-mux/state"), + ctx: ctx, + cancelCtx: cancelCtx, + deliverTxTree: deliverTxTree, + checkTxTree: checkTxTree, + stateRoot: *stateRoot, + storage: ldb, + statePruner: statePruner, + prunerClosedCh: make(chan struct{}), + prunerNotifyCh: channels.NewRingChannel(1), + haltEpochHeight: cfg.HaltEpochHeight, + minGasPrice: minGasPrice, + ownTxSigner: cfg.OwnTxSigner, + ownTxSignerAddress: staking.NewAddress(cfg.OwnTxSigner), + disableCheckTx: cfg.DisableCheckTx, + metricsClosedCh: make(chan struct{}), } // Refresh consensus parameters when loading state if we are past genesis. diff --git a/go/consensus/tendermint/api/state.go b/go/consensus/tendermint/api/state.go index 262439d90ff..1fb1531f101 100644 --- a/go/consensus/tendermint/api/state.go +++ b/go/consensus/tendermint/api/state.go @@ -14,6 +14,7 @@ import ( consensusGenesis "github.com/oasisprotocol/oasis-core/go/consensus/genesis" epochtime "github.com/oasisprotocol/oasis-core/go/epochtime/api" genesis "github.com/oasisprotocol/oasis-core/go/genesis/api" + staking "github.com/oasisprotocol/oasis-core/go/staking/api" storage "github.com/oasisprotocol/oasis-core/go/storage/api" "github.com/oasisprotocol/oasis-core/go/storage/mkvs" ) @@ -58,6 +59,9 @@ type ApplicationState interface { // OwnTxSigner returns the transaction signer identity of the local node. OwnTxSigner() signature.PublicKey + // OwnTxSignerAddress returns the transaction signer's staking address of the local node. + OwnTxSignerAddress() staking.Address + // NewContext creates a new application processing context. NewContext(mode ContextMode, now time.Time) *Context } @@ -95,8 +99,9 @@ type MockApplicationStateConfig struct { type mockApplicationState struct { cfg MockApplicationStateConfig - blockCtx *BlockContext - tree mkvs.Tree + blockCtx *BlockContext + tree mkvs.Tree + ownTxSignerAddress staking.Address } func (ms *mockApplicationState) Storage() storage.LocalBackend { @@ -139,6 +144,10 @@ func (ms *mockApplicationState) OwnTxSigner() signature.PublicKey { return ms.cfg.OwnTxSigner } +func (ms *mockApplicationState) OwnTxSignerAddress() staking.Address { + return ms.ownTxSignerAddress +} + func (ms *mockApplicationState) ConsensusParameters() *consensusGenesis.Parameters { return &ms.cfg.Genesis.Consensus.Parameters } @@ -171,9 +180,10 @@ func NewMockApplicationState(cfg MockApplicationStateConfig) ApplicationState { } return &mockApplicationState{ - cfg: cfg, - blockCtx: blockCtx, - tree: tree, + cfg: cfg, + blockCtx: blockCtx, + tree: tree, + ownTxSignerAddress: staking.NewAddress(cfg.OwnTxSigner), } }