Skip to content

Commit

Permalink
go: rename compute -> executor
Browse files Browse the repository at this point in the history
  • Loading branch information
pro-wh committed Jan 8, 2020
1 parent e50b619 commit b0fddd3
Show file tree
Hide file tree
Showing 60 changed files with 867 additions and 868 deletions.
14 changes: 7 additions & 7 deletions go/consensus/tendermint/apps/roothash/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ var (
// merge discrepancy detected events (value is a CBOR serialized
// ValueMergeDiscrepancyDetected).
KeyMergeDiscrepancyDetected = []byte("merge-discrepancy")
// KeyComputeDiscrepancyDetected is an ABCI event attribute key for
// KeyExecutionDiscrepancyDetected is an ABCI event attribute key for
// merge discrepancy detected events (value is a CBOR serialized
// ValueComputeDiscrepancyDetected).
KeyComputeDiscrepancyDetected = []byte("compute-discrepancy")
// ValueExecutionDiscrepancyDetected).
KeyExecutionDiscrepancyDetected = []byte("execution-discrepancy")
// KeyFinalized is an ABCI event attribute key for finalized blocks
// (value is a CBOR serialized ValueFinalized).
KeyFinalized = []byte("finalized")
Expand All @@ -48,9 +48,9 @@ type ValueMergeDiscrepancyDetected struct {
ID common.Namespace `json:"id"`
}

// ValueComputeDiscrepancyDetected is the value component of a
// ValueExecutionDiscrepancyDetected is the value component of a
// TagMergeDiscrepancyDetected.
type ValueComputeDiscrepancyDetected struct {
ID common.Namespace `json:"id"`
Event roothash.ComputeDiscrepancyDetectedEvent `json:"event"`
type ValueExecutionDiscrepancyDetected struct {
ID common.Namespace `json:"id"`
Event roothash.ExecutionDiscrepancyDetectedEvent `json:"event"`
}
94 changes: 47 additions & 47 deletions go/consensus/tendermint/apps/roothash/roothash.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,49 +122,49 @@ func (app *rootHashApplication) onCommitteeChanged(ctx *abci.Context, epoch epoc
// of all committees. We need this to be able to quickly see if any
// committee members have changed.
//
// We first include the current epoch, then all compute committee member
// We first include the current epoch, then all executor committee member
// hashes and then the merge committee member hash:
//
// [little-endian epoch]
// "compute committees follow"
// [compute committe 1 members hash]
// [compute committe 2 members hash]
// "executor committees follow"
// [executor committe 1 members hash]
// [executor committe 2 members hash]
// ...
// [compute committe n members hash]
// [executor committe n members hash]
// "merge committee follows"
// [merge committee members hash]
//
var committeeIDParts [][]byte
var rawEpoch [8]byte
binary.LittleEndian.PutUint64(rawEpoch[:], uint64(epoch))
committeeIDParts = append(committeeIDParts, rawEpoch[:])
committeeIDParts = append(committeeIDParts, []byte("compute committees follow"))
committeeIDParts = append(committeeIDParts, []byte("executor committees follow"))

// NOTE: There will later be multiple compute committees.
var computeCommittees []*scheduler.Committee
cc1, err := schedState.Committee(scheduler.KindCompute, rtID)
// NOTE: There will later be multiple executor committees.
var executorCommittees []*scheduler.Committee
xc1, err := schedState.Committee(scheduler.KindExecutor, rtID)
if err != nil {
app.logger.Error("checkCommittees: failed to get compute committee from scheduler",
app.logger.Error("checkCommittees: failed to get executor committee from scheduler",
"err", err,
"runtime", rtID,
)
continue
}
if cc1 != nil {
computeCommittees = append(computeCommittees, cc1)
if xc1 != nil {
executorCommittees = append(executorCommittees, xc1)
}

computePool := &commitment.MultiPool{
executorPool := &commitment.MultiPool{
Committees: make(map[hash.Hash]*commitment.Pool),
}
if len(computeCommittees) == 0 {
app.logger.Warn("checkCommittees: no compute committees",
if len(executorCommittees) == 0 {
app.logger.Warn("checkCommittees: no executor committees",
"runtime", rtID,
)
}
for _, computeCommittee := range computeCommittees {
computeNodeInfo := make(map[signature.PublicKey]commitment.NodeInfo)
for idx, n := range computeCommittee.Members {
for _, executorCommittee := range executorCommittees {
executorNodeInfo := make(map[signature.PublicKey]commitment.NodeInfo)
for idx, n := range executorCommittee.Members {
var nodeRuntime *node.Runtime
node, err1 := regState.Node(n.PublicKey)
if err1 != nil {
Expand All @@ -185,18 +185,18 @@ func (app *rootHashApplication) onCommitteeChanged(ctx *abci.Context, epoch epoc
)
continue
}
computeNodeInfo[n.PublicKey] = commitment.NodeInfo{
executorNodeInfo[n.PublicKey] = commitment.NodeInfo{
CommitteeNode: idx,
Runtime: nodeRuntime,
}
}
computeCommitteeID := computeCommittee.EncodedMembersHash()
committeeIDParts = append(committeeIDParts, computeCommitteeID[:])
executorCommitteeID := executorCommittee.EncodedMembersHash()
committeeIDParts = append(committeeIDParts, executorCommitteeID[:])

computePool.Committees[computeCommitteeID] = &commitment.Pool{
executorPool.Committees[executorCommitteeID] = &commitment.Pool{
Runtime: rtState.Runtime,
Committee: computeCommittee,
NodeInfo: computeNodeInfo,
Committee: executorCommittee,
NodeInfo: executorNodeInfo,
}
}

Expand Down Expand Up @@ -259,7 +259,7 @@ func (app *rootHashApplication) onCommitteeChanged(ctx *abci.Context, epoch epoc
)

rtState.Timer.Stop(ctx)
rtState.Round = roothashState.NewRound(committeeID, computePool, &mergePool, blk)
rtState.Round = roothashState.NewRound(committeeID, executorPool, &mergePool, blk)

// Emit an empty epoch transition block in the new round. This is required so that
// the clients can be sure what state is final when an epoch transition occurs.
Expand Down Expand Up @@ -309,13 +309,13 @@ func (app *rootHashApplication) ExecuteTx(ctx *abci.Context, tx *transaction.Tra
state := roothashState.NewMutableState(ctx.State())

switch tx.Method {
case roothash.MethodComputeCommit:
var cc roothash.ComputeCommit
if err := cbor.Unmarshal(tx.Body, &cc); err != nil {
case roothash.MethodExecutorCommit:
var xc roothash.ExecutorCommit
if err := cbor.Unmarshal(tx.Body, &xc); err != nil {
return err
}

return app.commit(ctx, state, cc.ID, &cc)
return app.commit(ctx, state, xc.ID, &xc)
case roothash.MethodMergeCommit:
var mc roothash.MergeCommit
if err := cbor.Unmarshal(tx.Body, &mc); err != nil {
Expand Down Expand Up @@ -476,8 +476,8 @@ func (app *rootHashApplication) FireTimer(ctx *abci.Context, timer *abci.Timer)
panic(err)
}
}
for _, pool := range rtState.Round.ComputePool.GetTimeoutCommittees(ctx.Now()) {
app.tryFinalizeCompute(ctx, runtime, rtState, pool, true)
for _, pool := range rtState.Round.ExecutorPool.GetTimeoutCommittees(ctx.Now()) {
app.tryFinalizeExecute(ctx, runtime, rtState, pool, true)
}

return nil
Expand Down Expand Up @@ -583,12 +583,12 @@ func (app *rootHashApplication) commit(
return err
}
}
case *roothash.ComputeCommit:
case *roothash.ExecutorCommit:
pools := make(map[*commitment.Pool]bool)
for _, commit := range c.Commits {
var pool *commitment.Pool
if pool, err = rtState.Round.AddComputeCommitment(&commit, sv); err != nil {
logger.Error("failed to add compute commitment to round",
if pool, err = rtState.Round.AddExecutorCommitment(&commit, sv); err != nil {
logger.Error("failed to add executor commitment to round",
"err", err,
"round", blockNr,
)
Expand All @@ -598,10 +598,10 @@ func (app *rootHashApplication) commit(
pools[pool] = true
}

// Try to finalize compute rounds.
// Try to finalize execute rounds.
if !ctx.IsCheckOnly() {
for pool := range pools {
app.tryFinalizeCompute(ctx, runtime, rtState, pool, false)
app.tryFinalizeExecute(ctx, runtime, rtState, pool, false)
}
}
default:
Expand Down Expand Up @@ -639,7 +639,7 @@ func (app *rootHashApplication) updateTimer(
}
}

func (app *rootHashApplication) tryFinalizeCompute(
func (app *rootHashApplication) tryFinalizeExecute(
ctx *abci.Context,
runtime *registry.Runtime,
rtState *roothashState.RuntimeState,
Expand All @@ -654,22 +654,22 @@ func (app *rootHashApplication) tryFinalizeCompute(
defer app.updateTimer(ctx, runtime, rtState, blockNr)

if rtState.Round.Finalized {
app.logger.Error("attempted to finalize compute when block already finalized",
app.logger.Error("attempted to finalize execute when block already finalized",
"round", blockNr,
"committee_id", committeeID,
)
return
}

_, err := pool.TryFinalize(ctx.Now(), runtime.Compute.RoundTimeout, forced, true)
_, err := pool.TryFinalize(ctx.Now(), runtime.Executor.RoundTimeout, forced, true)
switch err {
case nil:
// No error -- there is no discrepancy. But only the merge committee
// can make progress even if we have all compute commitments.
// can make progress even if we have all executor commitments.

// TODO: Check if we need to punish the merge committee.

app.logger.Warn("no compute discrepancy, but only merge committee can make progress",
app.logger.Warn("no execution discrepancy, but only merge committee can make progress",
"round", blockNr,
"committee_id", committeeID,
)
Expand All @@ -684,20 +684,20 @@ func (app *rootHashApplication) tryFinalizeCompute(
return
case commitment.ErrDiscrepancyDetected:
// Discrepancy has been detected.
app.logger.Warn("compute discrepancy detected",
app.logger.Warn("execution discrepancy detected",
"round", blockNr,
"committee_id", committeeID,
logging.LogEvent, roothash.LogEventComputeDiscrepancyDetected,
logging.LogEvent, roothash.LogEventExecutionDiscrepancyDetected,
)

tagV := ValueComputeDiscrepancyDetected{
tagV := ValueExecutionDiscrepancyDetected{
ID: runtime.ID,
Event: roothash.ComputeDiscrepancyDetectedEvent{
Event: roothash.ExecutionDiscrepancyDetectedEvent{
CommitteeID: pool.GetCommitteeID(),
Timeout: forced,
},
}
ctx.EmitEvent(tmapi.NewEventBuilder(app.Name()).Attribute(KeyComputeDiscrepancyDetected, cbor.Marshal(tagV)))
ctx.EmitEvent(tmapi.NewEventBuilder(app.Name()).Attribute(KeyExecutionDiscrepancyDetected, cbor.Marshal(tagV)))
return
default:
}
Expand Down Expand Up @@ -747,7 +747,7 @@ func (app *rootHashApplication) tryFinalizeMerge(
blk.Header.Timestamp = uint64(ctx.Now().Unix())

rtState.Round.MergePool.ResetCommitments()
rtState.Round.ComputePool.ResetCommitments()
rtState.Round.ExecutorPool.ResetCommitments()
rtState.Round.Finalized = true

return blk
Expand Down
20 changes: 10 additions & 10 deletions go/consensus/tendermint/apps/roothash/state/round.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,40 +11,40 @@ import (

// Round is a roothash round.
type Round struct {
CommitteeID hash.Hash `json:"committee_id"`
ComputePool *commitment.MultiPool `json:"compute_pool"`
MergePool *commitment.Pool `json:"merge_pool"`
CommitteeID hash.Hash `json:"committee_id"`
ExecutorPool *commitment.MultiPool `json:"executor_pool"`
MergePool *commitment.Pool `json:"merge_pool"`

CurrentBlock *block.Block `json:"current_block"`
Finalized bool `json:"finalized"`
}

func (r *Round) Reset() {
r.ComputePool.ResetCommitments()
r.ExecutorPool.ResetCommitments()
r.MergePool.ResetCommitments()
r.Finalized = false
}

func (r *Round) GetNextTimeout() (timeout time.Time) {
timeout = r.ComputePool.GetNextTimeout()
timeout = r.ExecutorPool.GetNextTimeout()
if timeout.IsZero() || (!r.MergePool.NextTimeout.IsZero() && r.MergePool.NextTimeout.Before(timeout)) {
timeout = r.MergePool.NextTimeout
}
return
}

func (r *Round) AddComputeCommitment(commitment *commitment.ComputeCommitment, sv commitment.SignatureVerifier) (*commitment.Pool, error) {
func (r *Round) AddExecutorCommitment(commitment *commitment.ExecutorCommitment, sv commitment.SignatureVerifier) (*commitment.Pool, error) {
if r.Finalized {
return nil, errors.New("tendermint/roothash: round is already finalized, can't commit")
}
return r.ComputePool.AddComputeCommitment(r.CurrentBlock, sv, commitment)
return r.ExecutorPool.AddExecutorCommitment(r.CurrentBlock, sv, commitment)
}

func (r *Round) AddMergeCommitment(commitment *commitment.MergeCommitment, sv commitment.SignatureVerifier) error {
if r.Finalized {
return errors.New("tendermint/roothash: round is already finalized, can't commit")
}
return r.MergePool.AddMergeCommitment(r.CurrentBlock, sv, commitment, r.ComputePool)
return r.MergePool.AddMergeCommitment(r.CurrentBlock, sv, commitment, r.ExecutorPool)
}

func (r *Round) Transition(blk *block.Block) {
Expand All @@ -54,14 +54,14 @@ func (r *Round) Transition(blk *block.Block) {

func NewRound(
committeeID hash.Hash,
computePool *commitment.MultiPool,
executorPool *commitment.MultiPool,
mergePool *commitment.Pool,
blk *block.Block,
) *Round {
r := &Round{
CommitteeID: committeeID,
CurrentBlock: blk,
ComputePool: computePool,
ExecutorPool: executorPool,
MergePool: mergePool,
}
r.Reset()
Expand Down
18 changes: 9 additions & 9 deletions go/consensus/tendermint/apps/scheduler/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import (
var (
_ abci.Application = (*schedulerApplication)(nil)

rngContextCompute = []byte("EkS-ABCI-Compute")
rngContextExecutor = []byte("EkS-ABCI-Compute")
rngContextStorage = []byte("EkS-ABCI-Storage")
rngContextTransactionScheduler = []byte("EkS-ABCI-TransactionScheduler")
rngContextMerge = []byte("EkS-ABCI-Merge")
Expand Down Expand Up @@ -215,7 +215,7 @@ func (app *schedulerApplication) BeginBlock(ctx *abci.Context, request types.Req
}

kinds := []scheduler.CommitteeKind{
scheduler.KindCompute,
scheduler.KindExecutor,
scheduler.KindStorage,
scheduler.KindTransactionScheduler,
scheduler.KindMerge,
Expand Down Expand Up @@ -339,7 +339,7 @@ func (app *schedulerApplication) FireTimer(ctx *abci.Context, t *abci.Timer) err
return errors.New("tendermint/scheduler: unexpected timer")
}

func (app *schedulerApplication) isSuitableComputeWorker(n *node.Node, rt *registry.Runtime, ts time.Time) bool {
func (app *schedulerApplication) isSuitableExecutorWorker(n *node.Node, rt *registry.Runtime, ts time.Time) bool {
if !n.HasRoles(node.RoleComputeWorker) {
return false
}
Expand Down Expand Up @@ -419,7 +419,7 @@ func (app *schedulerApplication) isSuitableMergeWorker(n *node.Node, rt *registr
// For non-fatal problems, save a problem condition to the state and return successfully.
func (app *schedulerApplication) electCommittee(ctx *abci.Context, request types.RequestBeginBlock, epoch epochtime.EpochTime, beacon []byte, entityStake *stakeAccumulator, entitiesEligibleForReward map[signature.PublicKey]bool, rt *registry.Runtime, nodes []*node.Node, kind scheduler.CommitteeKind) error {
// Only generic compute runtimes need to elect all the committees.
if !rt.IsCompute() && kind != scheduler.KindCompute {
if !rt.IsCompute() && kind != scheduler.KindExecutor {
return nil
}

Expand All @@ -436,12 +436,12 @@ func (app *schedulerApplication) electCommittee(ctx *abci.Context, request types
)

switch kind {
case scheduler.KindCompute:
rngCtx = rngContextCompute
case scheduler.KindExecutor:
rngCtx = rngContextExecutor
threshold = staking.KindCompute
isSuitableFn = app.isSuitableComputeWorker
workerSize = int(rt.Compute.GroupSize)
backupSize = int(rt.Compute.GroupBackupSize)
isSuitableFn = app.isSuitableExecutorWorker
workerSize = int(rt.Executor.GroupSize)
backupSize = int(rt.Executor.GroupBackupSize)
case scheduler.KindMerge:
rngCtx = rngContextMerge
threshold = staking.KindCompute
Expand Down
6 changes: 3 additions & 3 deletions go/consensus/tendermint/roothash/roothash.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,8 +432,8 @@ func (tb *tendermintBackend) worker(ctx context.Context) { // nolint: gocyclo

notifiers := tb.getRuntimeNotifiers(value.ID)
notifiers.eventNotifier.Broadcast(&api.Event{MergeDiscrepancyDetected: &value.Event})
} else if bytes.Equal(pair.GetKey(), app.KeyComputeDiscrepancyDetected) {
var value app.ValueComputeDiscrepancyDetected
} else if bytes.Equal(pair.GetKey(), app.KeyExecutionDiscrepancyDetected) {
var value app.ValueExecutionDiscrepancyDetected
if err := cbor.Unmarshal(pair.GetValue(), &value); err != nil {
tb.logger.Error("worker: failed to get discrepancy from tag",
"err", err,
Expand All @@ -442,7 +442,7 @@ func (tb *tendermintBackend) worker(ctx context.Context) { // nolint: gocyclo
}

notifiers := tb.getRuntimeNotifiers(value.ID)
notifiers.eventNotifier.Broadcast(&api.Event{ComputeDiscrepancyDetected: &value.Event})
notifiers.eventNotifier.Broadcast(&api.Event{ExecutionDiscrepancyDetected: &value.Event})
}
}
}
Expand Down
Loading

0 comments on commit b0fddd3

Please sign in to comment.