Skip to content

Commit

Permalink
Merge PR: swap websocket v1.6.7 (#2936)
Browse files Browse the repository at this point in the history
* swap websocket v1.6.7

* fix fmt

* no valUpdate
  • Loading branch information
chengzhinei authored Jan 29, 2023
1 parent 0c241bf commit 6a909fd
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 27 deletions.
12 changes: 5 additions & 7 deletions libs/tendermint/consensus/consensus_commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,13 +239,6 @@ func (cs *State) finalizeCommit(height int64) {

cs.trc.Pin("%s-%d", trace.RunTx, cs.Round)

// publish event of the latest block time
if types.EnableEventBlockTime {
validators := cs.Validators.Copy()
validators.IncrementProposerPriority(1)
cs.blockExec.FireBlockTimeEvents(height, blockTime.UnixMilli(), validators.Proposer.Address)
}

if iavl.EnableAsyncCommit {
cs.handleCommitGapOffset(height)
}
Expand Down Expand Up @@ -296,6 +289,11 @@ func (cs *State) finalizeCommit(height int64) {
cs.Logger.Error("Can't get private validator pubkey", "err", err)
}

// publish event
if types.EnableEventBlockTime {
cs.blockExec.FireBlockTimeEvents(block.Height, len(block.Txs), false)
}

cs.trc.Pin("Waiting")
// cs.StartTime is already set.
// Schedule Round0 to start soon.
Expand Down
36 changes: 20 additions & 16 deletions libs/tendermint/state/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
mempl "github.com/okex/exchain/libs/tendermint/mempool"
"github.com/okex/exchain/libs/tendermint/proxy"
"github.com/okex/exchain/libs/tendermint/types"
tmtime "github.com/okex/exchain/libs/tendermint/types/time"
dbm "github.com/okex/exchain/libs/tm-db"
"github.com/tendermint/go-amino"
)
Expand Down Expand Up @@ -239,6 +240,19 @@ func (blockExec *BlockExecutor) ApplyBlock(

abciResponses, duration, err := blockExec.runAbci(block, deltaInfo)

// Events are fired after runAbci.
// publish event
if types.EnableEventBlockTime {
blockExec.FireBlockTimeEvents(block.Height, len(block.Txs), true)
}
// NOTE: if we crash between Commit and Save, events wont be fired during replay
if !blockExec.isNullIndexer {
blockExec.eventsChan <- event{
block: block,
abciRsp: abciResponses,
}
}

trace.GetElapsedInfo().AddInfo(trace.LastRun, fmt.Sprintf("%dms", duration.Milliseconds()))
trace.GetApplyBlockWorkloadSttistic().Add(trace.LastRun, time.Now(), duration)

Expand Down Expand Up @@ -300,16 +314,6 @@ func (blockExec *BlockExecutor) ApplyBlock(
blockExec.logger.Debug("SaveState", "state", &state)
fail.Fail() // XXX

// Events are fired after everything else.
// NOTE: if we crash between Commit and Save, events wont be fired during replay
if !blockExec.isNullIndexer {
blockExec.eventsChan <- event{
block: block,
abciRsp: abciResponses,
vals: validatorUpdates,
}
}

dc.postApplyBlock(block.Height, deltaInfo, abciResponses, commitResp.DeltaMap, blockExec.isFastSync)

return state, retainHeight, nil
Expand Down Expand Up @@ -744,13 +748,13 @@ func fireEvents(
})
}

if len(validatorUpdates) > 0 {
eventBus.PublishEventValidatorSetUpdates(
types.EventDataValidatorSetUpdates{ValidatorUpdates: validatorUpdates})
}
//if len(validatorUpdates) > 0 {
// eventBus.PublishEventValidatorSetUpdates(
// types.EventDataValidatorSetUpdates{ValidatorUpdates: validatorUpdates})
//}
}

func (blockExec *BlockExecutor) FireBlockTimeEvents(height, blockTime int64, address types.Address) {
func (blockExec *BlockExecutor) FireBlockTimeEvents(height int64, txNum int, available bool) {
blockExec.eventBus.PublishEventLatestBlockTime(
types.EventDataBlockTime{Height: height, BlockTime: blockTime, NextProposer: address})
types.EventDataBlockTime{Height: height, TimeNow: tmtime.Now().UnixMilli(), TxNum: txNum, Available: available})
}
3 changes: 2 additions & 1 deletion libs/tendermint/state/execution_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package state_test

import (
"context"
"testing"
"time"

Expand Down Expand Up @@ -319,6 +318,7 @@ func TestUpdateValidators(t *testing.T) {
}

// TestEndBlockValidatorUpdates ensures we update validator set and send an event.
/*
func TestEndBlockValidatorUpdates(t *testing.T) {
app := &testApp{}
cc := proxy.NewLocalClientCreator(app)
Expand Down Expand Up @@ -384,6 +384,7 @@ func TestEndBlockValidatorUpdates(t *testing.T) {
t.Fatal("Did not receive EventValidatorSetUpdates within 1 sec.")
}
}
*/

// TestEndBlockValidatorUpdatesResultingInEmptySet checks that processing validator updates that
// would result in empty set causes no panic, an error is raised and NextValidators is not updated
Expand Down
7 changes: 4 additions & 3 deletions libs/tendermint/types/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,10 @@ type EventDataRmPendingTx struct {

// latest blockTime
type EventDataBlockTime struct {
Height int64
BlockTime int64
NextProposer Address
Height int64
TimeNow int64
TxNum int
Available bool
}

// NOTE: This goes into the replay WAL
Expand Down

0 comments on commit 6a909fd

Please sign in to comment.