Skip to content

Commit

Permalink
go/consensus/tendermint/api: Add OwnTxSignerAddress() to app state
Browse files Browse the repository at this point in the history
Add OwnTxSignerAddress() to ApplicationState.
  • Loading branch information
tjanez committed Jun 11, 2020
1 parent f30c411 commit 5501d83
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 23 deletions.
3 changes: 3 additions & 0 deletions .changelog/2940.feature.6.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
go/consensus/tendermint/api: Add `OwnTxSignerAddress()` to `ApplicationState`

It returns the transaction signer's staking address of the local node.
43 changes: 25 additions & 18 deletions go/consensus/tendermint/abci/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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{}
}
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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.
Expand Down
20 changes: 15 additions & 5 deletions go/consensus/tendermint/api/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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),
}
}

Expand Down

0 comments on commit 5501d83

Please sign in to comment.