diff --git a/block/manager.go b/block/manager.go index 8aecbe38ac..1b499b9e1f 100644 --- a/block/manager.go +++ b/block/manager.go @@ -15,8 +15,6 @@ 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" @@ -422,7 +420,7 @@ func (m *Manager) getCommit(header types.Header) (*types.Commit, error) { func (m *Manager) publishBlock(ctx context.Context) error { var lastCommit *types.Commit - var lastHeaderHash header.Hash + var lastHeaderHash types.Hash var err error height := m.store.Height() newHeight := height + 1 @@ -572,7 +570,7 @@ func updateState(s *types.State, res *abci.ResponseInitChain) { // the state. We don't set appHash since we don't want the genesis doc app hash // recorded in the genesis block. We should probably just remove GenesisDoc.AppHash. if len(res.AppHash) > 0 { - copy(s.AppHash[:], res.AppHash) + s.AppHash = res.AppHash } if res.ConsensusParams != nil { @@ -597,7 +595,7 @@ func updateState(s *types.State, res *abci.ResponseInitChain) { s.Version.Consensus.App = s.ConsensusParams.Version.AppVersion } // We update the last results hash with the empty hash, to conform with RFC-6962. - copy(s.LastResultsHash[:], merkle.HashFromByteSlices(nil)) + s.LastResultsHash = merkle.HashFromByteSlices(nil) if len(res.Validators) > 0 { vals, err := tmtypes.PB2TM.ValidatorUpdates(res.Validators) diff --git a/conv/abci/block.go b/conv/abci/block.go index 28fb4ab90f..62f4345e14 100644 --- a/conv/abci/block.go +++ b/conv/abci/block.go @@ -50,19 +50,19 @@ func ToABCIHeader(header *types.Header) (tmtypes.Header, error) { Height: int64(header.Height()), Time: header.Time(), LastBlockID: tmtypes.BlockID{ - Hash: header.LastHeaderHash[:], + Hash: tmbytes.HexBytes(header.LastHeaderHash), PartSetHeader: tmtypes.PartSetHeader{ Total: 0, Hash: nil, }, }, - LastCommitHash: header.LastCommitHash[:], - DataHash: header.DataHash[:], - ValidatorsHash: header.AggregatorsHash[:], + LastCommitHash: tmbytes.HexBytes(header.LastCommitHash), + DataHash: tmbytes.HexBytes(header.DataHash), + ValidatorsHash: tmbytes.HexBytes(header.AggregatorsHash), NextValidatorsHash: nil, - ConsensusHash: header.ConsensusHash[:], - AppHash: header.AppHash[:], - LastResultsHash: header.LastResultsHash[:], + ConsensusHash: tmbytes.HexBytes(header.ConsensusHash), + AppHash: tmbytes.HexBytes(header.AppHash), + LastResultsHash: tmbytes.HexBytes(header.LastResultsHash), EvidenceHash: new(tmtypes.EvidenceData).Hash(), ProposerAddress: header.ProposerAddress, ChainID: header.ChainID(), @@ -92,7 +92,7 @@ func ToABCIBlock(block *types.Block) (*tmtypes.Block, error) { for i := range block.Data.Txs { abciBlock.Data.Txs[i] = tmtypes.Tx(block.Data.Txs[i]) } - abciBlock.Header.DataHash = block.Header.DataHash[:] + abciBlock.Header.DataHash = tmbytes.HexBytes(block.Header.DataHash) return &abciBlock, nil } diff --git a/da/test/da_test.go b/da/test/da_test.go index a9ff52253c..eee4369dc6 100644 --- a/da/test/da_test.go +++ b/da/test/da_test.go @@ -244,6 +244,7 @@ func getRandomBlock(height uint64, nTxs int) *types.Block { BaseHeader: types.BaseHeader{ Height: height, }, + AggregatorsHash: make([]byte, 32), }, Data: types.Data{ Txs: make(types.Txs, nTxs), @@ -252,7 +253,7 @@ func getRandomBlock(height uint64, nTxs int) *types.Block { }, }, } - copy(block.Header.AppHash[:], getRandomBytes(32)) + block.Header.AppHash = getRandomBytes(32) for i := 0; i < nTxs; i++ { block.Data.Txs[i] = getRandomTx() diff --git a/go.mod b/go.mod index 781535e5f9..314e12e777 100644 --- a/go.mod +++ b/go.mod @@ -25,7 +25,7 @@ require ( github.com/stretchr/testify v1.8.1 github.com/tendermint/tendermint v0.34.21 go.uber.org/multierr v1.9.0 - golang.org/x/net v0.0.0-20221014081412-f15817d10f9b + golang.org/x/net v0.5.0 google.golang.org/grpc v1.50.1 google.golang.org/protobuf v1.28.1 ) @@ -161,11 +161,11 @@ require ( go.uber.org/atomic v1.10.0 // indirect go.uber.org/zap v1.22.0 // indirect golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e // indirect - golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect + golang.org/x/mod v0.7.0 // indirect golang.org/x/sync v0.1.0 // indirect - golang.org/x/sys v0.0.0-20221013171732-95e765b1cc43 // indirect - golang.org/x/text v0.4.0 // indirect - golang.org/x/tools v0.1.12 // indirect + golang.org/x/sys v0.4.0 // indirect + golang.org/x/text v0.6.0 // indirect + golang.org/x/tools v0.5.0 // indirect google.golang.org/genproto v0.0.0-20221024183307-1bc688fe9f3e // indirect gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect diff --git a/go.sum b/go.sum index 76806ccf45..24a853f0bd 100644 --- a/go.sum +++ b/go.sum @@ -743,6 +743,8 @@ golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 h1:6zppjxzCulZykYSLyVDYbneBfbaBIQPYMevg0bEwv2s= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= +golang.org/x/mod v0.7.0 h1:LapD9S96VoQRhi/GrNTqeBJFrUjs5UHCAtTlgwA5oZA= +golang.org/x/mod v0.7.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20181011144130-49bb7cea24b1/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -795,6 +797,8 @@ golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su golang.org/x/net v0.0.0-20220624214902-1bab6f366d9e/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/net v0.0.0-20221014081412-f15817d10f9b h1:tvrvnPFcdzp294diPnrdZZZ8XUt2Tyj7svb7X52iDuU= golang.org/x/net v0.0.0-20221014081412-f15817d10f9b/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk= +golang.org/x/net v0.5.0 h1:GyT4nK/YDHSqa1c4753ouYCDajOYKTja9Xb/OHtgvSw= +golang.org/x/net v0.5.0/go.mod h1:DivGGAXEgPSlEBzxGzZI+ZLohi+xUj054jfeKui00ws= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20181017192945-9dcd33a902f4/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20181203162652-d668ce993890/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= @@ -896,6 +900,8 @@ golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20221010170243-090e33056c14/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20221013171732-95e765b1cc43 h1:OK7RB6t2WQX54srQQYSXMW8dF5C6/8+oA/s5QBmmto4= golang.org/x/sys v0.0.0-20221013171732-95e765b1cc43/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.4.0 h1:Zr2JFtRQNX3BCZ8YtxRE9hNJYC8J6I1MVbMg6owUp18= +golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -908,6 +914,8 @@ golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.4.0 h1:BrVqGRd7+k1DiOgtnFvAkoQEWQvBc25ouMJM6429SFg= golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/text v0.6.0 h1:3XmdazWV+ubf7QgHSTWeykHOci5oeekaGJBLkrkaw4k= +golang.org/x/text v0.6.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= @@ -969,6 +977,8 @@ golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.6-0.20210726203631-07bc1bf47fb2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.12 h1:VveCTK38A2rkS8ZqFY25HIDFscX5X9OoEhJd3quQmXU= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= +golang.org/x/tools v0.5.0 h1:+bSpV5HIeWkuvgaMfI3UmKRThoTA5ODJTUd8T17NO+4= +golang.org/x/tools v0.5.0/go.mod h1:N+Kgy78s5I24c24dU8OfWNEotWjutIs8SnJvn5IDq+k= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/node/full_client.go b/node/full_client.go index 07c6e9d3b6..c77f62c5fc 100644 --- a/node/full_client.go +++ b/node/full_client.go @@ -19,7 +19,7 @@ import ( "github.com/tendermint/tendermint/proxy" rpcclient "github.com/tendermint/tendermint/rpc/client" ctypes "github.com/tendermint/tendermint/rpc/core/types" - "github.com/tendermint/tendermint/types" + tmtypes "github.com/tendermint/tendermint/types" "github.com/tendermint/tendermint/version" rconfig "github.com/celestiaorg/rollmint/config" @@ -46,7 +46,7 @@ var _ rpcclient.Client = &FullClient{} // // This is the type that is used in communication between cosmos-sdk app and rollmint. type FullClient struct { - *types.EventBus + *tmtypes.EventBus config *config.RPCConfig node *FullNode @@ -96,7 +96,7 @@ func (c *FullClient) ABCIQueryWithOptions(ctx context.Context, path string, data // BroadcastTxCommit returns with the responses from CheckTx and DeliverTx. // More: https://docs.tendermint.com/master/rpc/#/Tx/broadcast_tx_commit -func (c *FullClient) BroadcastTxCommit(ctx context.Context, tx types.Tx) (*ctypes.ResultBroadcastTxCommit, error) { +func (c *FullClient) BroadcastTxCommit(ctx context.Context, tx tmtypes.Tx) (*ctypes.ResultBroadcastTxCommit, error) { // This implementation corresponds to Tendermints implementation from rpc/core/mempool.go. // ctx.RemoteAddr godoc: If neither HTTPReq nor WSConn is set, an empty string is returned. // This code is a local client, so we can assume that subscriber is "" @@ -111,7 +111,7 @@ func (c *FullClient) BroadcastTxCommit(ctx context.Context, tx types.Tx) (*ctype // Subscribe to tx being committed in block. subCtx, cancel := context.WithTimeout(ctx, subscribeTimeout) defer cancel() - q := types.EventQueryTxFor(tx) + q := tmtypes.EventQueryTxFor(tx) deliverTxSub, err := c.EventBus.Subscribe(subCtx, subscriber, q) if err != nil { err = fmt.Errorf("failed to subscribe to tx: %w", err) @@ -152,7 +152,7 @@ func (c *FullClient) BroadcastTxCommit(ctx context.Context, tx types.Tx) (*ctype // Wait for the tx to be included in a block or timeout. select { case msg := <-deliverTxSub.Out(): // The tx was included in a block. - deliverTxRes := msg.Data().(types.EventDataTx) + deliverTxRes := msg.Data().(tmtypes.EventDataTx) return &ctypes.ResultBroadcastTxCommit{ CheckTx: *checkTxRes, DeliverTx: deliverTxRes.Result, @@ -187,7 +187,7 @@ func (c *FullClient) BroadcastTxCommit(ctx context.Context, tx types.Tx) (*ctype // BroadcastTxAsync returns right away, with no response. Does not wait for // CheckTx nor DeliverTx results. // More: https://docs.tendermint.com/master/rpc/#/Tx/broadcast_tx_async -func (c *FullClient) BroadcastTxAsync(ctx context.Context, tx types.Tx) (*ctypes.ResultBroadcastTx, error) { +func (c *FullClient) BroadcastTxAsync(ctx context.Context, tx tmtypes.Tx) (*ctypes.ResultBroadcastTx, error) { err := c.node.Mempool.CheckTx(tx, nil, mempool.TxInfo{}) if err != nil { return nil, err @@ -203,7 +203,7 @@ func (c *FullClient) BroadcastTxAsync(ctx context.Context, tx types.Tx) (*ctypes // BroadcastTxSync returns with the response from CheckTx. Does not wait for // DeliverTx result. // More: https://docs.tendermint.com/master/rpc/#/Tx/broadcast_tx_sync -func (c *FullClient) BroadcastTxSync(ctx context.Context, tx types.Tx) (*ctypes.ResultBroadcastTx, error) { +func (c *FullClient) BroadcastTxSync(ctx context.Context, tx tmtypes.Tx) (*ctypes.ResultBroadcastTx, error) { resCh := make(chan *abci.Response, 1) err := c.node.Mempool.CheckTx(tx, func(res *abci.Response) { resCh <- res @@ -250,7 +250,7 @@ func (c *FullClient) Subscribe(ctx context.Context, subscriber, query string, ou outCap = outCapacity[0] } - var sub types.Subscription + var sub tmtypes.Subscription if outCap > 0 { sub, err = c.EventBus.Subscribe(ctx, subscriber, q, outCap) } else { @@ -322,7 +322,7 @@ func (c *FullClient) BlockchainInfo(ctx context.Context, minHeight, maxHeight in } c.Logger.Debug("BlockchainInfo", "maxHeight", maxHeight, "minHeight", minHeight) - blocks := make([]*types.BlockMeta, 0, maxHeight-minHeight+1) + blocks := make([]*tmtypes.BlockMeta, 0, maxHeight-minHeight+1) for height := maxHeight; height >= minHeight; height-- { block, err := c.node.Store.LoadBlock(uint64(height)) if err != nil { @@ -425,9 +425,9 @@ func (c *FullClient) Block(ctx context.Context, height *int64) (*ctypes.ResultBl return nil, err } return &ctypes.ResultBlock{ - BlockID: types.BlockID{ - Hash: hash[:], - PartSetHeader: types.PartSetHeader{ + BlockID: tmtypes.BlockID{ + Hash: tmbytes.HexBytes(hash), + PartSetHeader: tmtypes.PartSetHeader{ Total: 0, Hash: nil, }, @@ -448,9 +448,9 @@ func (c *FullClient) BlockByHash(ctx context.Context, hash []byte) (*ctypes.Resu return nil, err } return &ctypes.ResultBlock{ - BlockID: types.BlockID{ + BlockID: tmtypes.BlockID{ Hash: hash, - PartSetHeader: types.PartSetHeader{ + PartSetHeader: tmtypes.PartSetHeader{ Total: 0, Hash: nil, }, @@ -541,13 +541,13 @@ func (c *FullClient) Tx(ctx context.Context, hash []byte, prove bool) (*ctypes.R height := res.Height index := res.Index - var proof types.TxProof + var proof tmtypes.TxProof if prove { block, _ := c.node.Store.LoadBlock(uint64(height)) blockProof := block.Data.Txs.Proof(int(index)) // XXX: overflow on 32-bit machines - proof = types.TxProof{ + proof = tmtypes.TxProof{ RootHash: blockProof.RootHash, - Data: types.Tx(blockProof.Data), + Data: tmtypes.Tx(blockProof.Data), Proof: blockProof.Proof, } } @@ -610,14 +610,14 @@ func (c *FullClient) TxSearch(ctx context.Context, query string, prove bool, pag for i := skipCount; i < skipCount+pageSize; i++ { r := results[i] - var proof types.TxProof + var proof tmtypes.TxProof /*if prove { block := nil //env.BlockStore.LoadBlock(r.Height) proof = block.Data.Txs.Proof(int(r.Index)) // XXX: overflow on 32-bit machines }*/ apiResults = append(apiResults, &ctypes.ResultTx{ - Hash: types.Tx(r.Tx).Hash(), + Hash: tmtypes.Tx(r.Tx).Hash(), Height: r.Height, Index: r.Index, TxResult: r.Result, @@ -682,7 +682,7 @@ func (c *FullClient) BlockSearch(ctx context.Context, query string, page, perPag } blocks = append(blocks, &ctypes.ResultBlock{ Block: block, - BlockID: types.BlockID{ + BlockID: tmtypes.BlockID{ Hash: block.Hash(), }, }) @@ -735,12 +735,12 @@ func (c *FullClient) Status(ctx context.Context) (*ctypes.ResultStatus, error) { }, }, SyncInfo: ctypes.SyncInfo{ - LatestBlockHash: latest.Header.DataHash[:], - LatestAppHash: latest.Header.AppHash[:], + LatestBlockHash: tmbytes.HexBytes(latest.Header.DataHash), + LatestAppHash: tmbytes.HexBytes(latest.Header.AppHash), LatestBlockHeight: latest.Header.Height(), LatestBlockTime: latest.Header.Time(), - EarliestBlockHash: initial.Header.DataHash[:], - EarliestAppHash: initial.Header.AppHash[:], + EarliestBlockHash: tmbytes.HexBytes(initial.Header.DataHash), + EarliestAppHash: tmbytes.HexBytes(initial.Header.AppHash), EarliestBlockHeight: initial.Header.Height(), EarliestBlockTime: initial.Header.Time(), CatchingUp: true, // the client is always syncing in the background to the latest height @@ -755,7 +755,7 @@ func (c *FullClient) Status(ctx context.Context) (*ctypes.ResultStatus, error) { } // BroadcastEvidence is not yet implemented. -func (c *FullClient) BroadcastEvidence(ctx context.Context, evidence types.Evidence) (*ctypes.ResultBroadcastEvidence, error) { +func (c *FullClient) BroadcastEvidence(ctx context.Context, evidence tmtypes.Evidence) (*ctypes.ResultBroadcastEvidence, error) { return &ctypes.ResultBroadcastEvidence{ Hash: evidence.Hash(), }, nil @@ -787,7 +787,7 @@ func (c *FullClient) UnconfirmedTxs(ctx context.Context, limitPtr *int) (*ctypes // CheckTx executes a new transaction against the application to determine its validity. // // If valid, the tx is automatically added to the mempool. -func (c *FullClient) CheckTx(ctx context.Context, tx types.Tx) (*ctypes.ResultCheckTx, error) { +func (c *FullClient) CheckTx(ctx context.Context, tx tmtypes.Tx) (*ctypes.ResultCheckTx, error) { res, err := c.appClient().CheckTxSync(abci.RequestCheckTx{Tx: tx}) if err != nil { return nil, err @@ -795,7 +795,7 @@ func (c *FullClient) CheckTx(ctx context.Context, tx types.Tx) (*ctypes.ResultCh return &ctypes.ResultCheckTx{ResponseCheckTx: *res}, nil } -func (c *FullClient) eventsRoutine(sub types.Subscription, subscriber string, q tmpubsub.Query, outc chan<- ctypes.ResultEvent) { +func (c *FullClient) eventsRoutine(sub tmtypes.Subscription, subscriber string, q tmpubsub.Query, outc chan<- ctypes.ResultEvent) { defer close(outc) for { select { @@ -827,7 +827,7 @@ func (c *FullClient) eventsRoutine(sub types.Subscription, subscriber string, q } // Try to resubscribe with exponential backoff. -func (c *FullClient) resubscribe(subscriber string, q tmpubsub.Query) types.Subscription { +func (c *FullClient) resubscribe(subscriber string, q tmpubsub.Query) tmtypes.Subscription { attempts := 0 for { if !c.IsRunning() { diff --git a/node/full_client_test.go b/node/full_client_test.go index 114b685f9d..047bbda901 100644 --- a/node/full_client_test.go +++ b/node/full_client_test.go @@ -381,7 +381,7 @@ func TestGetBlockByHash(t *testing.T) { require.NoError(err) require.NotNil(retrievedBlock) assert.Equal(abciBlock, retrievedBlock.Block) - assert.Equal(abciBlock.Hash(), retrievedBlock.Block.Header.Hash()) + assert.Equal(abciBlock.Hash(), retrievedBlock.Block.Hash()) blockHash := block.Header.Hash() blockResp, err := rpc.BlockByHash(context.Background(), blockHash[:]) @@ -724,6 +724,7 @@ func getRandomBlockWithProposer(height uint64, nTxs int, proposerAddr []byte) *t }, Version: types.Version{Block: types.InitStateVersion.Consensus.Block}, ProposerAddress: proposerAddr, + AggregatorsHash: make([]byte, 32), }, Data: types.Data{ Txs: make(types.Txs, nTxs), @@ -732,7 +733,7 @@ func getRandomBlockWithProposer(height uint64, nTxs int, proposerAddr []byte) *t }, }, } - copy(block.Header.AppHash[:], getRandomBytes(32)) + block.Header.AppHash = getRandomBytes(32) for i := 0; i < nTxs; i++ { block.Data.Txs[i] = getRandomTx() @@ -749,7 +750,9 @@ func getRandomBlockWithProposer(height uint64, nTxs int, proposerAddr []byte) *t if err != nil { return nil } - copy(block.Header.LastCommitHash[:], tmprotoLC.Hash()) + lastCommitHash := make(types.Hash, 32) + copy(lastCommitHash, tmprotoLC.Hash().Bytes()) + block.Header.LastCommitHash = lastCommitHash return block } diff --git a/state/executor.go b/state/executor.go index 846125c251..c14c4a536f 100644 --- a/state/executor.go +++ b/state/executor.go @@ -16,8 +16,6 @@ import ( tmtypes "github.com/tendermint/tendermint/types" "go.uber.org/multierr" - "github.com/celestiaorg/go-header" - abciconv "github.com/celestiaorg/rollmint/conv/abci" "github.com/celestiaorg/rollmint/log" "github.com/celestiaorg/rollmint/mempool" @@ -89,7 +87,7 @@ func (e *BlockExecutor) InitChain(genesis *tmtypes.GenesisDoc) (*abci.ResponseIn } // CreateBlock reaps transactions from mempool and builds a block. -func (e *BlockExecutor) CreateBlock(height uint64, lastCommit *types.Commit, lastHeaderHash header.Hash, state types.State) *types.Block { +func (e *BlockExecutor) CreateBlock(height uint64, lastCommit *types.Commit, lastHeaderHash types.Hash, state types.State) *types.Block { maxBytes := state.ConsensusParams.Block.MaxBytes maxGas := state.ConsensusParams.Block.MaxGas @@ -109,8 +107,8 @@ func (e *BlockExecutor) CreateBlock(height uint64, lastCommit *types.Commit, las NamespaceID: e.namespaceID, //LastHeaderHash: lastHeaderHash, //LastCommitHash: lastCommitHash, - DataHash: [32]byte{}, - ConsensusHash: [32]byte{}, + DataHash: make(types.Hash, 32), + ConsensusHash: make(types.Hash, 32), AppHash: state.AppHash, LastResultsHash: state.LastResultsHash, ProposerAddress: e.proposerAddress, @@ -122,9 +120,9 @@ func (e *BlockExecutor) CreateBlock(height uint64, lastCommit *types.Commit, las }, LastCommit: *lastCommit, } - copy(block.Header.LastCommitHash[:], e.getLastCommitHash(lastCommit, &block.Header)) - copy(block.Header.LastHeaderHash[:], lastHeaderHash) - copy(block.Header.AggregatorsHash[:], state.Validators.Hash()) + block.Header.LastCommitHash = e.getLastCommitHash(lastCommit, &block.Header) + block.Header.LastHeaderHash = lastHeaderHash + block.Header.AggregatorsHash = state.Validators.Hash() return block } @@ -174,7 +172,7 @@ func (e *BlockExecutor) Commit(ctx context.Context, state types.State, block *ty return []byte{}, 0, err } - copy(state.AppHash[:], appHash[:]) + state.AppHash = appHash err = e.publishEvents(resp, block, state) if err != nil { @@ -231,7 +229,7 @@ func (e *BlockExecutor) updateState(state types.State, block *types.Block, abciR LastHeightValidatorsChanged: lastHeightValSetChanged, ConsensusParams: state.ConsensusParams, LastHeightConsensusParamsChanged: state.LastHeightConsensusParamsChanged, - AppHash: [32]byte{}, + AppHash: make(types.Hash, 32), } copy(s.LastResultsHash[:], tmtypes.NewResults(abciResponses.DeliverTxs).Hash()) diff --git a/store/store.go b/store/store.go index f31bbb1a38..d09cc39c92 100644 --- a/store/store.go +++ b/store/store.go @@ -107,7 +107,7 @@ func (s *DefaultStore) LoadBlock(height uint64) (*types.Block, error) { } // LoadBlockByHash returns block with given block header hash, or error if it's not found in Store. -func (s *DefaultStore) LoadBlockByHash(hash header.Hash) (*types.Block, error) { +func (s *DefaultStore) LoadBlockByHash(hash types.Hash) (*types.Block, error) { blockData, err := s.db.Get(s.ctx, ds.NewKey(getBlockKey(hash))) if err != nil { return nil, fmt.Errorf("failed to load block data: %w", err) @@ -154,7 +154,7 @@ func (s *DefaultStore) LoadCommit(height uint64) (*types.Commit, error) { } // LoadCommitByHash returns commit for a block with given block header hash, or error if it's not found in Store. -func (s *DefaultStore) LoadCommitByHash(hash header.Hash) (*types.Commit, error) { +func (s *DefaultStore) LoadCommitByHash(hash types.Hash) (*types.Commit, error) { commitData, err := s.db.Get(s.ctx, ds.NewKey(getCommitKey(hash))) if err != nil { return nil, fmt.Errorf("failed to retrieve commit from hash %v: %w", hash, err) @@ -241,11 +241,11 @@ func (s *DefaultStore) loadHashFromIndex(height uint64) (header.Hash, error) { return blob, nil } -func getBlockKey(hash header.Hash) string { +func getBlockKey(hash types.Hash) string { return GenerateKey([]interface{}{blockPrefix, hex.EncodeToString(hash[:])}) } -func getCommitKey(hash header.Hash) string { +func getCommitKey(hash types.Hash) string { return GenerateKey([]interface{}{commitPrefix, hex.EncodeToString(hash[:])}) } diff --git a/store/store_test.go b/store/store_test.go index be2218569a..49b22904fc 100644 --- a/store/store_test.go +++ b/store/store_test.go @@ -205,6 +205,7 @@ func getRandomBlock(height uint64, nTxs int) *types.Block { BaseHeader: types.BaseHeader{ Height: height, }, + AggregatorsHash: make([]byte, 32), }, Data: types.Data{ Txs: make(types.Txs, nTxs), diff --git a/store/types.go b/store/types.go index aff4565710..6a9aa2205d 100644 --- a/store/types.go +++ b/store/types.go @@ -4,8 +4,6 @@ import ( tmstate "github.com/tendermint/tendermint/proto/tendermint/state" tmtypes "github.com/tendermint/tendermint/types" - "github.com/celestiaorg/go-header" - "github.com/celestiaorg/rollmint/types" ) @@ -23,7 +21,7 @@ type Store interface { // LoadBlock returns block at given height, or error if it's not found in Store. LoadBlock(height uint64) (*types.Block, error) // LoadBlockByHash returns block with given block header hash, or error if it's not found in Store. - LoadBlockByHash(hash header.Hash) (*types.Block, error) + LoadBlockByHash(hash types.Hash) (*types.Block, error) // SaveBlockResponses saves block responses (events, tx responses, validator set updates, etc) in Store. SaveBlockResponses(height uint64, responses *tmstate.ABCIResponses) error @@ -34,7 +32,7 @@ type Store interface { // LoadCommit returns commit for a block at given height, or error if it's not found in Store. LoadCommit(height uint64) (*types.Commit, error) // LoadCommitByHash returns commit for a block with given block header hash, or error if it's not found in Store. - LoadCommitByHash(hash header.Hash) (*types.Commit, error) + LoadCommitByHash(hash types.Hash) (*types.Commit, error) // UpdateState updates state saved in Store. Only one State is stored. // If there is no State in Store, state will be saved. diff --git a/types/block.go b/types/block.go index e77797045b..9e2682cc25 100644 --- a/types/block.go +++ b/types/block.go @@ -2,8 +2,6 @@ package types import ( "encoding" - - "github.com/celestiaorg/go-header" ) type NamespaceID [8]byte @@ -42,7 +40,7 @@ type EvidenceData struct { // Commit contains evidence of block creation. type Commit struct { Height uint64 - HeaderHash header.Hash + HeaderHash Hash Signatures []Signature // most of the time this is a single signature } diff --git a/types/hashing.go b/types/hashing.go index c91d435410..80530740ee 100644 --- a/types/hashing.go +++ b/types/hashing.go @@ -1,14 +1,13 @@ package types import ( + tmbytes "github.com/tendermint/tendermint/libs/bytes" tmversion "github.com/tendermint/tendermint/proto/tendermint/version" tmtypes "github.com/tendermint/tendermint/types" - - "github.com/celestiaorg/go-header" ) // Hash returns ABCI-compatible hash of a header. -func (h *Header) Hash() header.Hash { +func (h *Header) Hash() Hash { abciHeader := tmtypes.Header{ Version: tmversion.Consensus{ Block: h.Version.Block, @@ -17,29 +16,27 @@ func (h *Header) Hash() header.Hash { Height: int64(h.Height()), Time: h.Time(), LastBlockID: tmtypes.BlockID{ - Hash: h.LastHeaderHash[:], + Hash: tmbytes.HexBytes(h.LastHeaderHash), PartSetHeader: tmtypes.PartSetHeader{ Total: 0, Hash: nil, }, }, - LastCommitHash: h.LastCommitHash[:], - DataHash: h.DataHash[:], - ValidatorsHash: h.AggregatorsHash[:], + LastCommitHash: tmbytes.HexBytes(h.LastCommitHash), + DataHash: tmbytes.HexBytes(h.DataHash), + ValidatorsHash: tmbytes.HexBytes(h.AggregatorsHash), NextValidatorsHash: nil, - ConsensusHash: h.ConsensusHash[:], - AppHash: h.AppHash[:], - LastResultsHash: h.LastResultsHash[:], + ConsensusHash: tmbytes.HexBytes(h.ConsensusHash), + AppHash: tmbytes.HexBytes(h.AppHash), + LastResultsHash: tmbytes.HexBytes(h.LastResultsHash), EvidenceHash: new(tmtypes.EvidenceData).Hash(), ProposerAddress: h.ProposerAddress, ChainID: h.ChainID(), } - return header.Hash(abciHeader.Hash()) + return Hash(abciHeader.Hash()) } // Hash returns ABCI-compatible hash of a block. -func (b *Block) Hash() [32]byte { - var hash [32]byte - copy(hash[:], b.Header.Hash()) - return hash +func (b *Block) Hash() Hash { + return b.Header.Hash() } diff --git a/types/header.go b/types/header.go index b01f76c5d6..557ad29146 100644 --- a/types/header.go +++ b/types/header.go @@ -9,6 +9,8 @@ import ( "github.com/celestiaorg/go-header" ) +type Hash = header.Hash + // BaseHeader contains the most basic data of a header type BaseHeader struct { // Height represents the block height (aka block number) of a given header @@ -30,18 +32,18 @@ type Header struct { NamespaceID NamespaceID // prev block info - LastHeaderHash [32]byte + LastHeaderHash Hash // hashes of block data - LastCommitHash [32]byte // commit from aggregator(s) from the last block - DataHash [32]byte // Block.Data root aka Transactions - ConsensusHash [32]byte // consensus params for current block - AppHash [32]byte // state after applying txs from the current block + LastCommitHash Hash // commit from aggregator(s) from the last block + DataHash Hash // Block.Data root aka Transactions + ConsensusHash Hash // consensus params for current block + AppHash Hash // state after applying txs from the current block // Root hash of all results from the txs from the previous block. // This is ABCI specific but smart-contract chains require some way of committing // to transaction receipts/results. - LastResultsHash [32]byte + LastResultsHash Hash // Note that the address can be derived from the pubkey which can be derived // from the signature when using secp256k. @@ -50,7 +52,7 @@ type Header struct { ProposerAddress []byte // original proposer of the block // Hash of block aggregator set, at a time of block creation - AggregatorsHash [32]byte + AggregatorsHash Hash } func (h *Header) New() header.Header { @@ -65,7 +67,7 @@ func (h *Header) Height() int64 { return int64(h.BaseHeader.Height) } -func (h *Header) LastHeader() header.Hash { +func (h *Header) LastHeader() Hash { return h.LastHeaderHash[:] } diff --git a/types/serialization.go b/types/serialization.go index 78865c6d1a..d07bb5fa62 100644 --- a/types/serialization.go +++ b/types/serialization.go @@ -213,27 +213,13 @@ func (h *Header) FromProto(other *pb.Header) error { } h.BaseHeader.Height = other.Height h.BaseHeader.Time = other.Time - if !safeCopy(h.LastHeaderHash[:], other.LastHeaderHash) { - return errors.New("invalid length of 'LastHeaderHash'") - } - if !safeCopy(h.LastCommitHash[:], other.LastCommitHash) { - return errors.New("invalid length of 'LastCommitHash'") - } - if !safeCopy(h.DataHash[:], other.DataHash) { - return errors.New("invalid length of 'DataHash'") - } - if !safeCopy(h.ConsensusHash[:], other.ConsensusHash) { - return errors.New("invalid length of 'ConsensusHash'") - } - if !safeCopy(h.AppHash[:], other.AppHash) { - return errors.New("invalid length of 'AppHash'") - } - if !safeCopy(h.LastResultsHash[:], other.LastResultsHash) { - return errors.New("invalid length of 'LastResultsHash'") - } - if !safeCopy(h.AggregatorsHash[:], other.AggregatorsHash) { - return errors.New("invalid length of 'AggregatorsHash'") - } + h.LastHeaderHash = other.LastHeaderHash + h.LastCommitHash = other.LastCommitHash + h.DataHash = other.DataHash + h.ConsensusHash = other.ConsensusHash + h.AppHash = other.AppHash + h.LastResultsHash = other.LastResultsHash + h.AggregatorsHash = other.AggregatorsHash if len(other.ProposerAddress) > 0 { h.ProposerAddress = make([]byte, len(other.ProposerAddress)) copy(h.ProposerAddress, other.ProposerAddress) @@ -370,8 +356,8 @@ func (s *State) FromProto(other *pb.State) error { s.LastHeightValidatorsChanged = other.LastHeightValidatorsChanged s.ConsensusParams = other.ConsensusParams s.LastHeightConsensusParamsChanged = other.LastHeightConsensusParamsChanged - copy(s.LastResultsHash[:], other.LastResultsHash) - copy(s.AppHash[:], other.AppHash) + s.LastResultsHash = other.LastResultsHash + s.AppHash = other.AppHash return nil } diff --git a/types/serialization_test.go b/types/serialization_test.go index f4a8d8ed8a..206cc2f91e 100644 --- a/types/serialization_test.go +++ b/types/serialization_test.go @@ -23,9 +23,9 @@ func TestBlockSerializationRoundTrip(t *testing.T) { require := require.New(t) // create random hashes - h := [][32]byte{} + h := []Hash{} for i := 0; i < 8; i++ { - var h1 [32]byte + h1 := make(Hash, 32) n, err := rand.Read(h1[:]) require.Equal(32, n) require.NoError(err) @@ -156,8 +156,8 @@ func TestStateRoundTrip(t *testing.T) { }, }, LastHeightConsensusParamsChanged: 12345, - LastResultsHash: [32]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2}, - AppHash: [32]byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1}, + LastResultsHash: Hash{1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2}, + AppHash: Hash{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1}, }, }, } diff --git a/types/state.go b/types/state.go index 0499d272ef..0becaa6bf7 100644 --- a/types/state.go +++ b/types/state.go @@ -52,10 +52,10 @@ type State struct { LastHeightConsensusParamsChanged int64 // Merkle root of the results from executing prev block - LastResultsHash [32]byte + LastResultsHash Hash // the latest AppHash we've received from calling abci.Commit() - AppHash [32]byte + AppHash Hash } // NewFromGenesisDoc reads blockchain State from genesis. @@ -97,7 +97,7 @@ func NewFromGenesisDoc(genDoc *types.GenesisDoc) (State, error) { ConsensusParams: *genDoc.ConsensusParams, LastHeightConsensusParamsChanged: genDoc.InitialHeight, } - copy(s.AppHash[:], genDoc.AppHash) + s.AppHash = genDoc.AppHash.Bytes() return s, nil }