Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename best to latest #664

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion api/blocks/blocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
bft BFTEngine
}

const BEST_BLOCK_NAME = "latest"

Check failure on line 26 in api/blocks/blocks.go

View workflow job for this annotation

GitHub Actions / golangci-lint

don't use ALL_CAPS in Go names; use CamelCase (golint)

func New(repo *chain.Repository, bft BFTEngine) *Blocks {
return &Blocks{
repo,
Expand Down Expand Up @@ -85,7 +87,7 @@
}

func (b *Blocks) parseRevision(revision string) (interface{}, error) {
if revision == "" || revision == "best" {
if revision == "" || revision == BEST_BLOCK_NAME {

Check failure on line 90 in api/blocks/blocks.go

View workflow job for this annotation

GitHub Actions / golangci-lint

BEST_BLOCK_NAME contains underscore. You should use mixedCap or MixedCap. (nosnakecase)
return nil, nil
}
if revision == "finalized" {
Expand Down
2 changes: 1 addition & 1 deletion api/blocks/blocks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func TestBlock(t *testing.T) {
checkBlock(t, blk, rb)
assert.Equal(t, http.StatusOK, statusCode)

res, statusCode = httpGet(t, ts.URL+"/blocks/best")
res, statusCode = httpGet(t, ts.URL+"/blocks/latest")
if err := json.Unmarshal(res, &rb); err != nil {
t.Fatal(err)
}
Expand Down
3 changes: 2 additions & 1 deletion api/debug/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"github.com/ethereum/go-ethereum/rlp"
"github.com/gorilla/mux"
"github.com/pkg/errors"
"github.com/vechain/thor/v2/api/blocks"

Check failure on line 20 in api/debug/debug.go

View workflow job for this annotation

GitHub Actions / golangci-lint

import 'github.com/vechain/thor/v2/api/blocks' is not allowed from list 'Main' (depguard)
"github.com/vechain/thor/v2/api/utils"
"github.com/vechain/thor/v2/chain"
"github.com/vechain/thor/v2/consensus"
Expand Down Expand Up @@ -354,7 +355,7 @@
}

func (d *Debug) handleRevision(revision string) (*chain.BlockSummary, error) {
if revision == "" || revision == "best" {
if revision == "" || revision == blocks.BEST_BLOCK_NAME {

Check failure on line 358 in api/debug/debug.go

View workflow job for this annotation

GitHub Actions / golangci-lint

BEST_BLOCK_NAME contains underscore. You should use mixedCap or MixedCap. (nosnakecase)
return d.repo.BestBlockSummary(), nil
}
if len(revision) == 66 || len(revision) == 64 {
Expand Down
12 changes: 6 additions & 6 deletions api/doc/thor.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ paths:
- Blocks
summary: Retrieve block
description: |
by ID or number, or 'best' for latest block or 'finalized' for finalized block. If `expanded` query option is true, all transactions along with
by ID or number, or 'latest' for latest block or 'finalized' for finalized block. If `expanded` query option is true, all transactions along with
their receipts will be embedded under `transactions` field instead of ids.
responses:
'200':
Expand Down Expand Up @@ -1392,24 +1392,24 @@ components:
RevisionInQuery:
name: revision
in: query
description: can be block number or ID. best block is assumed if omitted.
description: can be block number or ID. latest block is assumed if omitted.
schema:
type: string

RevisionInPath:
name: revision
in: path
description: |
block ID or number, or 'best' stands for latest block, or 'finalized' stands for finalized block
block ID or number, or 'latest' stands for latest block, or 'finalized' stands for finalized block
required: true
schema:
type: string
example: best
example: latest

HeadInQuery:
name: head
in: query
description: ID of head block. best block is assumed if omitted
description: ID of head block. latest block is assumed if omitted
schema:
type: string

Expand Down Expand Up @@ -1457,7 +1457,7 @@ components:
name: pos
in: query
description: |
a saved block ID for resuming the subscription. best block ID is assumed if omitted.
a saved block ID for resuming the subscription. latest block ID is assumed if omitted.
schema:
type: string

Expand Down
2 changes: 1 addition & 1 deletion chain/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func NewRepository(db *muxdb.MuxDB, genesis *block.Block) (*Repository, error) {
}

if summary, err := repo.GetBlockSummary(bestID); err != nil {
return nil, errors.Wrap(err, "get best block")
return nil, errors.Wrap(err, "get latest block")
} else {
repo.bestSummary.Store(summary)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/thor/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ var (
apiBacktraceLimitFlag = cli.IntFlag{
Name: "api-backtrace-limit",
Value: 1000,
Usage: "limit the distance between 'position' and best block for subscriptions APIs",
Usage: "limit the distance between 'position' and latest block for subscriptions APIs",
}
apiAllowCustomTracerFlag = cli.BoolFlag{
Name: "api-allow-custom-tracer",
Expand Down
2 changes: 1 addition & 1 deletion cmd/thor/node/packer_loop.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func (n *Node) packerLoop(ctx context.Context) {

if (best.Number() == flow.ParentHeader().Number() && s1 != s2) ||
best.TotalScore() > flow.TotalScore() {
log.Debug("re-schedule packer due to new best block")
log.Debug("re-schedule packer due to new latest block")
goto RE_SCHEDULE
}
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/thor/solo/solo.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func (s *Solo) packing(pendingTxs tx.Transactions, onDemand bool) error {
realElapsed := mclock.Now() - startTime

if err := s.repo.SetBestBlockID(b.Header().ID()); err != nil {
return errors.WithMessage(err, "set best block")
return errors.WithMessage(err, "set latest block")
}

if !s.skipLogs {
Expand Down
22 changes: 11 additions & 11 deletions cmd/thor/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -538,12 +538,12 @@ func printStartupMessage1(
bestBlock := repo.BestBlockSummary()

fmt.Printf(`Starting %v
Network [ %v %v ]
Best block [ %v #%v @%v ]
Forks [ %v ]
Master [ %v ]
Beneficiary [ %v ]
Instance dir [ %v ]
Network [ %v %v ]
Latest block [ %v #%v @%v ]
Forks [ %v ]
Master [ %v ]
Beneficiary [ %v ]
Instance dir [ %v ]
`,
common.MakeName("Thor", fullVersion()),
gene.ID(), gene.Name(),
Expand Down Expand Up @@ -592,11 +592,11 @@ func printSoloStartupMessage(
bestBlock := repo.BestBlockSummary()

info := fmt.Sprintf(`Starting %v
Network [ %v %v ]
Best block [ %v #%v @%v ]
Forks [ %v ]
Data dir [ %v ]
API portal [ %v ]
Network [ %v %v ]
Latest block [ %v #%v @%v ]
Forks [ %v ]
Data dir [ %v ]
API portal [ %v ]
┌──────────────────┬───────────────────────────────────────────────────────────────────────────────┐
│ Mnemonic Words │ denial kitchen pet squirrel other broom bar gas better priority spoil cross │
└──────────────────┴───────────────────────────────────────────────────────────────────────────────┘
Expand Down
2 changes: 1 addition & 1 deletion comm/communicator.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func (c *Communicator) Sync(ctx context.Context, handler HandleBlockStream) {
break
}
// if more than 3 peers connected, we are assumed to be the best
log.Debug("synchronization done, best assumed")
log.Debug("synchronization done, latest assumed")
} else {
if err := download(ctx, c.repo, peer, best.Number(), handler); err != nil {
peer.logger.Debug("synchronization failed", "err", err)
Expand Down
4 changes: 2 additions & 2 deletions logdb/logdb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ func TestLogDB_NewestBlockID(t *testing.T) {
return b.Header().ID(), nil
},
}, {
"add empty block, best should remain unchanged",
"add empty block, latest should remain unchanged",
func() (thor.Bytes32, error) {
wanted := b.Header().ID()
b = new(block.Builder).ParentID(b.Header().ID()).Build()
Expand All @@ -295,7 +295,7 @@ func TestLogDB_NewestBlockID(t *testing.T) {
},
},
{
"add both event and transfer, best should change",
"add both event and transfer, latest should change",
func() (thor.Bytes32, error) {
b = new(block.Builder).
ParentID(b.Header().ID()).
Expand Down
Loading