Skip to content

Commit

Permalink
Integration with go-header (cosmos#685)
Browse files Browse the repository at this point in the history
Initial version of header interface is used to unblock work on go-header library.

Resolves cosmos#641.

<!-- 
Please provide an explanation of the PR, including the appropriate
context,
background, goal, and rationale. If there is an issue with this
information,
please provide a tl;dr and link the issue. 
-->
  • Loading branch information
tzdybal committed Jan 17, 2023
1 parent e5ec6a8 commit d8679cc
Show file tree
Hide file tree
Showing 21 changed files with 345 additions and 172 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: 1.17
go-version: 1.19
- name: golangci-lint
uses: golangci/golangci-lint-action@v3.3.1
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.17
go-version: 1.19

- name: Build
run: go build -v ./...
Expand Down
26 changes: 14 additions & 12 deletions block/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import (
tmtypes "github.com/tendermint/tendermint/types"
"go.uber.org/multierr"

"github.com/celestiaorg/go-header"

"github.com/celestiaorg/rollmint/config"
"github.com/celestiaorg/rollmint/da"
"github.com/celestiaorg/rollmint/log"
Expand Down Expand Up @@ -195,8 +197,8 @@ func (m *Manager) SyncLoop(ctx context.Context) {
case <-daTicker.C:
m.retrieveCond.Signal()
case header := <-m.HeaderInCh:
m.logger.Debug("block header received", "height", header.Header.Height, "hash", header.Header.Hash())
newHeight := header.Header.Height
m.logger.Debug("block header received", "height", header.Header.Height(), "hash", header.Header.Hash())
newHeight := header.Header.BaseHeader.Height
currentHeight := m.store.Height()
// in case of client reconnecting after being offline
// newHeight may be significantly larger than currentHeight
Expand All @@ -223,7 +225,7 @@ func (m *Manager) SyncLoop(ctx context.Context) {
"daHeight", daHeight,
"hash", block.Hash(),
)
m.syncCache[block.Header.Height] = block
m.syncCache[block.Header.BaseHeader.Height] = block
m.retrieveCond.Signal()

err := m.trySyncNextBlock(ctx, daHeight)
Expand Down Expand Up @@ -279,7 +281,7 @@ func (m *Manager) trySyncNextBlock(ctx context.Context, daHeight uint64) error {
}

if b1 != nil && commit != nil {
m.logger.Info("Syncing block", "height", b1.Header.Height)
m.logger.Info("Syncing block", "height", b1.Header.Height())
newState, responses, err := m.executor.ApplyBlock(ctx, m.lastState, b1)
if err != nil {
return fmt.Errorf("failed to ApplyBlock: %w", err)
Expand All @@ -292,9 +294,9 @@ func (m *Manager) trySyncNextBlock(ctx context.Context, daHeight uint64) error {
if err != nil {
return fmt.Errorf("failed to Commit: %w", err)
}
m.store.SetHeight(b1.Header.Height)
m.store.SetHeight(uint64(b1.Header.Height()))

err = m.store.SaveBlockResponses(b1.Header.Height, responses)
err = m.store.SaveBlockResponses(uint64(b1.Header.Height()), responses)
if err != nil {
return fmt.Errorf("failed to save block responses: %w", err)
}
Expand Down Expand Up @@ -412,22 +414,22 @@ func (m *Manager) getCommit(header types.Header) (*types.Commit, error) {
return nil, err
}
return &types.Commit{
Height: header.Height,
Height: uint64(header.Height()),
HeaderHash: header.Hash(),
Signatures: []types.Signature{sign},
}, nil
}

func (m *Manager) publishBlock(ctx context.Context) error {
var lastCommit *types.Commit
var lastHeaderHash [32]byte
var lastHeaderHash header.Hash
var err error
height := m.store.Height()
newHeight := height + 1

// this is a special case, when first block is produced - there is no previous commit
if newHeight == uint64(m.genesis.InitialHeight) {
lastCommit = &types.Commit{Height: height, HeaderHash: [32]byte{}}
lastCommit = &types.Commit{Height: height}
} else {
lastCommit, err = m.store.LoadCommit(height)
if err != nil {
Expand Down Expand Up @@ -499,7 +501,7 @@ func (m *Manager) publishBlock(ctx context.Context) error {
}

// SaveBlockResponses commits the DB tx
err = m.store.SaveBlockResponses(block.Header.Height, responses)
err = m.store.SaveBlockResponses(uint64(block.Header.Height()), responses)
if err != nil {
return err
}
Expand All @@ -515,13 +517,13 @@ func (m *Manager) publishBlock(ctx context.Context) error {
}

// SaveValidators commits the DB tx
err = m.store.SaveValidators(block.Header.Height, m.lastState.Validators)
err = m.store.SaveValidators(uint64(block.Header.Height()), m.lastState.Validators)
if err != nil {
return err
}

// Only update the stored height after successfully submitting to DA layer and committing to the DB
m.store.SetHeight(block.Header.Height)
m.store.SetHeight(uint64(block.Header.Height()))

m.publishSignedHeader(block, commit)

Expand Down
17 changes: 8 additions & 9 deletions conv/abci/block.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package abci

import (
"time"

tmbytes "github.com/tendermint/tendermint/libs/bytes"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
tmversion "github.com/tendermint/tendermint/proto/tendermint/version"
tmtypes "github.com/tendermint/tendermint/types"
Expand All @@ -18,8 +17,8 @@ func ToABCIHeaderPB(header *types.Header) (tmproto.Header, error) {
Block: header.Version.Block,
App: header.Version.App,
},
Height: int64(header.Height),
Time: time.Unix(int64(header.Time), 0),
Height: int64(header.Height()),
Time: header.Time(),
LastBlockId: tmproto.BlockID{
Hash: header.LastHeaderHash[:],
PartSetHeader: tmproto.PartSetHeader{
Expand All @@ -36,7 +35,7 @@ func ToABCIHeaderPB(header *types.Header) (tmproto.Header, error) {
LastResultsHash: header.LastResultsHash[:],
EvidenceHash: new(tmtypes.EvidenceData).Hash(),
ProposerAddress: header.ProposerAddress,
ChainID: header.ChainID,
ChainID: header.ChainID(),
}, nil
}

Expand All @@ -48,8 +47,8 @@ func ToABCIHeader(header *types.Header) (tmtypes.Header, error) {
Block: header.Version.Block,
App: header.Version.App,
},
Height: int64(header.Height),
Time: time.Unix(int64(header.Time), 0),
Height: int64(header.Height()),
Time: header.Time(),
LastBlockID: tmtypes.BlockID{
Hash: header.LastHeaderHash[:],
PartSetHeader: tmtypes.PartSetHeader{
Expand All @@ -66,7 +65,7 @@ func ToABCIHeader(header *types.Header) (tmtypes.Header, error) {
LastResultsHash: header.LastResultsHash[:],
EvidenceHash: new(tmtypes.EvidenceData).Hash(),
ProposerAddress: header.ProposerAddress,
ChainID: header.ChainID,
ChainID: header.ChainID(),
}, nil
}

Expand Down Expand Up @@ -122,7 +121,7 @@ func ToABCICommit(commit *types.Commit) *tmtypes.Commit {
Height: int64(commit.Height),
Round: 0,
BlockID: tmtypes.BlockID{
Hash: commit.HeaderHash[:],
Hash: tmbytes.HexBytes(commit.HeaderHash),
PartSetHeader: tmtypes.PartSetHeader{},
},
}
Expand Down
2 changes: 1 addition & 1 deletion da/mock/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func (m *DataAvailabilityLayerClient) SubmitBlock(ctx context.Context, block *ty
return da.ResultSubmitBlock{BaseResult: da.BaseResult{Code: da.StatusError, Message: err.Error()}}
}

err = m.dalcKV.Put(ctx, getKey(daHeight, block.Header.Height), hash[:])
err = m.dalcKV.Put(ctx, getKey(daHeight, uint64(block.Header.Height())), hash[:])
if err != nil {
return da.ResultSubmitBlock{BaseResult: da.BaseResult{Code: da.StatusError, Message: err.Error()}}
}
Expand Down
4 changes: 3 additions & 1 deletion da/test/da_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,9 @@ func doTestRetrieve(t *testing.T, dalc da.DataAvailabilityLayerClient) {
func getRandomBlock(height uint64, nTxs int) *types.Block {
block := &types.Block{
Header: types.Header{
Height: height,
BaseHeader: types.BaseHeader{
Height: height,
},
},
Data: types.Data{
Txs: make(types.Txs, nTxs),
Expand Down
9 changes: 5 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/celestiaorg/go-cnc v0.2.0
github.com/dgraph-io/badger/v3 v3.2103.5
github.com/go-kit/kit v0.12.0
github.com/gogo/protobuf v1.3.2
github.com/gogo/protobuf v1.3.3
github.com/google/orderedcode v0.0.1
github.com/gorilla/mux v1.8.0
github.com/gorilla/rpc v1.2.0
Expand Down Expand Up @@ -35,6 +35,7 @@ require (
github.com/benbjohnson/clock v1.3.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/btcsuite/btcd v0.22.1 // indirect
github.com/celestiaorg/go-header v0.0.0-20230103073037-63e9cfae040e // indirect
github.com/cespare/xxhash v1.1.0 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/cheekybits/genny v1.0.0 // indirect
Expand Down Expand Up @@ -70,7 +71,7 @@ require (
github.com/gtank/merlin v0.1.1 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/golang-lru v0.5.4 // indirect
github.com/hashicorp/golang-lru v0.5.5-0.20210104140557-80c98217689d // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/huin/goupnp v1.0.3 // indirect
github.com/inconshreveable/mousetrap v1.0.1 // indirect
Expand All @@ -85,7 +86,7 @@ require (
github.com/jmhodges/levigo v1.0.0 // indirect
github.com/jtolds/gls v4.20.0+incompatible // indirect
github.com/klauspost/compress v1.15.9 // indirect
github.com/klauspost/cpuid/v2 v2.1.0 // indirect
github.com/klauspost/cpuid/v2 v2.1.1 // indirect
github.com/koron/go-ssdp v0.0.3 // indirect
github.com/libp2p/go-buffer-pool v0.1.0 // indirect
github.com/libp2p/go-cidranger v1.1.0 // indirect
Expand Down Expand Up @@ -122,7 +123,7 @@ require (
github.com/multiformats/go-multiaddr-fmt v0.1.0 // indirect
github.com/multiformats/go-multibase v0.1.1 // indirect
github.com/multiformats/go-multicodec v0.6.0 // indirect
github.com/multiformats/go-multihash v0.2.1 // indirect
github.com/multiformats/go-multihash v0.2.2-0.20221030163302-608669da49b6 // indirect
github.com/multiformats/go-multistream v0.3.3 // indirect
github.com/multiformats/go-varint v0.0.6 // indirect
github.com/nxadm/tail v1.4.8 // indirect
Expand Down
8 changes: 8 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ github.com/btcsuite/btcutil v1.0.3-0.20201208143702-a53e38424cce h1:YtWJF7RHm2pY
github.com/buger/jsonparser v0.0.0-20181115193947-bf1c66bbce23/go.mod h1:bbYlZJ7hK1yFx9hf58LP0zeX7UjIGs20ufpu3evjr+s=
github.com/celestiaorg/go-cnc v0.2.0 h1:QBcWz1v6341r+5Urbr/eaCm9S8D2wwEwielKcwBc1Z4=
github.com/celestiaorg/go-cnc v0.2.0/go.mod h1:CZBVUhQnJnAVcfQnnEAqREF+PNWr97m/BhJ5fp1K44Q=
github.com/celestiaorg/go-header v0.0.0-20230103073037-63e9cfae040e h1:hSL6X6wbDjL8W8aiJvjR33cKAKMVCb7MN3zPgWpxFvg=
github.com/celestiaorg/go-header v0.0.0-20230103073037-63e9cfae040e/go.mod h1:DHwX+lgMeSjyLrjMD8qHFs4W6eWCD5RRfCQw9WYIalI=
github.com/celestiaorg/tendermint v0.34.22-0.20221013213714-8be9b54c8c21 h1:M1fprJ+U7Z3SZzDBeiuJ/vx21QgguOu+Ld9ALVDyLuY=
github.com/celestiaorg/tendermint v0.34.22-0.20221013213714-8be9b54c8c21/go.mod h1:zoyyiiihvTW8DnOr63YLxhYn/WK/QmE74CeIpS++hBE=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
Expand Down Expand Up @@ -282,6 +284,8 @@ github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hashicorp/golang-lru v0.5.4 h1:YDjusn29QI/Das2iO9M0BHnIbxPeyuCHsjMW+lJfyTc=
github.com/hashicorp/golang-lru v0.5.4/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4=
github.com/hashicorp/golang-lru v0.5.5-0.20210104140557-80c98217689d h1:dg1dEPuWpEqDnvIw251EVy4zlP8gWbsGj4BsUKCRpYs=
github.com/hashicorp/golang-lru v0.5.5-0.20210104140557-80c98217689d/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4=
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
Expand Down Expand Up @@ -343,6 +347,8 @@ github.com/klauspost/cpuid/v2 v2.0.4/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa02
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
github.com/klauspost/cpuid/v2 v2.1.0 h1:eyi1Ad2aNJMW95zcSbmGg7Cg6cq3ADwLpMAP96d8rF0=
github.com/klauspost/cpuid/v2 v2.1.0/go.mod h1:RVVoqg1df56z8g3pUjL/3lE5UfnlrJX8tyFgg4nqhuY=
github.com/klauspost/cpuid/v2 v2.1.1 h1:t0wUqjowdm8ezddV5k0tLWVklVuvLJpoHeb4WBdydm0=
github.com/klauspost/cpuid/v2 v2.1.1/go.mod h1:RVVoqg1df56z8g3pUjL/3lE5UfnlrJX8tyFgg4nqhuY=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/koron/go-ssdp v0.0.0-20191105050749-2e1c40ed0b5d/go.mod h1:5Ky9EC2xfoUKUor0Hjgi2BJhCSXJfMOFlmyYrVKGQMk=
Expand Down Expand Up @@ -468,6 +474,8 @@ github.com/multiformats/go-multihash v0.0.8/go.mod h1:YSLudS+Pi8NHE7o6tb3D8vrpKa
github.com/multiformats/go-multihash v0.0.13/go.mod h1:VdAWLKTwram9oKAatUcLxBNUjdtcVwxObEQBtRfuyjc=
github.com/multiformats/go-multihash v0.2.1 h1:aem8ZT0VA2nCHHk7bPJ1BjUbHNciqZC/d16Vve9l108=
github.com/multiformats/go-multihash v0.2.1/go.mod h1:WxoMcYG85AZVQUyRyo9s4wULvW5qrI9vb2Lt6evduFc=
github.com/multiformats/go-multihash v0.2.2-0.20221030163302-608669da49b6 h1:qLF997Rz0X1WvdcZ2r5CUkLZ2rvdiXwG1JRSrJZEAuE=
github.com/multiformats/go-multihash v0.2.2-0.20221030163302-608669da49b6/go.mod h1:kaHxr8TfO1cxIR/tYxgZ7e59HraJq8arEQQR8E/YNvI=
github.com/multiformats/go-multistream v0.3.3 h1:d5PZpjwRgVlbwfdTDjife7XszfZd8KYWfROYFlGcR8o=
github.com/multiformats/go-multistream v0.3.3/go.mod h1:ODRoqamLUsETKS9BNcII4gcRsJBU5VAwRIv7O39cEXg=
github.com/multiformats/go-varint v0.0.1/go.mod h1:3Ls8CIEsrijN6+B7PbrXRPxHRPuXSrVKRY101jdMZYE=
Expand Down
17 changes: 7 additions & 10 deletions rpc/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -435,10 +435,7 @@ func (c *Client) Block(ctx context.Context, height *int64) (*ctypes.ResultBlock,

// BlockByHash returns BlockID and block itself for given hash.
func (c *Client) BlockByHash(ctx context.Context, hash []byte) (*ctypes.ResultBlock, error) {
var h [32]byte
copy(h[:], hash)

block, err := c.node.Store.LoadBlockByHash(h)
block, err := c.node.Store.LoadBlockByHash(hash)
if err != nil {
return nil, err
}
Expand All @@ -449,7 +446,7 @@ func (c *Client) BlockByHash(ctx context.Context, hash []byte) (*ctypes.ResultBl
}
return &ctypes.ResultBlock{
BlockID: types.BlockID{
Hash: h[:],
Hash: hash,
PartSetHeader: types.PartSetHeader{
Total: 0,
Hash: nil,
Expand Down Expand Up @@ -703,7 +700,7 @@ func (c *Client) Status(ctx context.Context) (*ctypes.ResultStatus, error) {
return nil, fmt.Errorf("failed to find earliest block: %w", err)
}

validators, err := c.node.Store.LoadValidators(latest.Header.Height)
validators, err := c.node.Store.LoadValidators(uint64(latest.Header.Height()))
if err != nil {
return nil, fmt.Errorf("failed to fetch the validator info at latest block: %w", err)
}
Expand Down Expand Up @@ -737,12 +734,12 @@ func (c *Client) Status(ctx context.Context) (*ctypes.ResultStatus, error) {
SyncInfo: ctypes.SyncInfo{
LatestBlockHash: latest.Header.DataHash[:],
LatestAppHash: latest.Header.AppHash[:],
LatestBlockHeight: int64(latest.Header.Height),
LatestBlockTime: time.Unix(0, int64(latest.Header.Time)),
LatestBlockHeight: latest.Header.Height(),
LatestBlockTime: latest.Header.Time(),
EarliestBlockHash: initial.Header.DataHash[:],
EarliestAppHash: initial.Header.AppHash[:],
EarliestBlockHeight: int64(initial.Header.Height),
EarliestBlockTime: time.Unix(0, int64(initial.Header.Time)),
EarliestBlockHeight: initial.Header.Height(),
EarliestBlockTime: initial.Header.Time(),
CatchingUp: true, // the client is always syncing in the background to the latest height
},
ValidatorInfo: ctypes.ValidatorInfo{
Expand Down
Loading

0 comments on commit d8679cc

Please sign in to comment.