Skip to content

Commit 2efe202

Browse files
authored
deps: bump go-header (#800)
Depends on #799 Unifies `VerifyAdjacent` and `VerifyNonAdjacent` into `Verify`
1 parent c6d3972 commit 2efe202

File tree

5 files changed

+44
-66
lines changed

5 files changed

+44
-66
lines changed

go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ go 1.18
44

55
require (
66
github.com/celestiaorg/go-cnc v0.3.0
7-
github.com/celestiaorg/go-header v0.1.0
7+
github.com/celestiaorg/go-header v0.2.1
88
github.com/dgraph-io/badger/v3 v3.2103.5
99
github.com/go-kit/kit v0.12.0
1010
github.com/gogo/protobuf v1.3.3
@@ -156,6 +156,7 @@ require (
156156
go.etcd.io/bbolt v1.3.6 // indirect
157157
go.opencensus.io v0.24.0 // indirect
158158
go.opentelemetry.io/otel v1.11.2 // indirect
159+
go.opentelemetry.io/otel/metric v0.34.0 // indirect
159160
go.opentelemetry.io/otel/trace v1.11.2 // indirect
160161
go.uber.org/atomic v1.10.0 // indirect
161162
go.uber.org/dig v1.15.0 // indirect

go.sum

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@ github.com/celestiaorg/go-cnc v0.3.0 h1:eAVPNHGpx+2sBO7NZyQ1+VW8rzf6W4FQDlSq6aqS
109109
github.com/celestiaorg/go-cnc v0.3.0/go.mod h1:zYzvHudSd1iNPuHBMyvZ1YvWou5aT9JXgtch9Tkaf70=
110110
github.com/celestiaorg/go-header v0.1.0 h1:K/atYWwZ/bjMLJ/Apy0dokbREa8BGgxUMiMjhRHlF4E=
111111
github.com/celestiaorg/go-header v0.1.0/go.mod h1:AR7GQ1519TDLEFxRC0rt9emq1IvhU+Nf+1Ufe3JI3nA=
112+
github.com/celestiaorg/go-header v0.2.0 h1:UnufpDXQGLpP40SyiwfZLRT7alKLmo3lraPaJtsV8qI=
113+
github.com/celestiaorg/go-header v0.2.0/go.mod h1:6XKf0yhoEQqfKQTZnyTZjTjF5jH5Wq9uO9AvDMkdYbs=
114+
github.com/celestiaorg/go-header v0.2.1 h1:h6EiEcrA7K9dg5bRNe7aNQ13rDAL4/wRB5jujMGP1Ho=
115+
github.com/celestiaorg/go-header v0.2.1/go.mod h1:6XKf0yhoEQqfKQTZnyTZjTjF5jH5Wq9uO9AvDMkdYbs=
112116
github.com/celestiaorg/go-libp2p-messenger v0.2.0 h1:/0MuPDcFamQMbw9xTZ73yImqgTO3jHV7wKHvWD/Irao=
113117
github.com/celestiaorg/go-libp2p-messenger v0.2.0/go.mod h1:s9PIhMi7ApOauIsfBcQwbr7m+HBzmVfDIS+QLdgzDSo=
114118
github.com/celestiaorg/tendermint v0.34.22-0.20221202214355-3605c597500d h1:OH9dp6WWotp53aG58xSdLWd+F1Znf3DhA0BadyJO4Aw=
@@ -1055,6 +1059,8 @@ go.opencensus.io v0.24.0 h1:y73uSU6J157QMP2kn2r30vwW1A2W2WFwSCGnAVxeaD0=
10551059
go.opencensus.io v0.24.0/go.mod h1:vNK8G9p7aAivkbmorf4v+7Hgx+Zs0yY+0fOtgBfjQKo=
10561060
go.opentelemetry.io/otel v1.11.2 h1:YBZcQlsVekzFsFbjygXMOXSs6pialIZxcjfO/mBDmR0=
10571061
go.opentelemetry.io/otel v1.11.2/go.mod h1:7p4EUV+AqgdlNV9gL97IgUZiVR3yrFXYo53f9BM3tRI=
1062+
go.opentelemetry.io/otel/metric v0.34.0 h1:MCPoQxcg/26EuuJwpYN1mZTeCYAUGx8ABxfW07YkjP8=
1063+
go.opentelemetry.io/otel/metric v0.34.0/go.mod h1:ZFuI4yQGNCupurTXCwkeD/zHBt+C2bR7bw5JqUm/AP8=
10581064
go.opentelemetry.io/otel/trace v1.11.2 h1:Xf7hWSF2Glv0DE3MH7fBHvtpSBsjcBUe5MYAmZM/+y0=
10591065
go.opentelemetry.io/otel/trace v1.11.2/go.mod h1:4N+yC7QEz7TTsG9BSRLNAa63eg5E06ObSbKPmxQ/pKA=
10601066
go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=

node/header_exchange.go

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func (hExService *HeaderExchangeService) initOrAppendHeaderStore(ctx context.Con
6969
if header.Height() == hExService.genesis.InitialHeight {
7070
err = hExService.headerStore.Init(ctx, header)
7171
} else {
72-
_, err = hExService.headerStore.Append(ctx, header)
72+
err = hExService.headerStore.Append(ctx, header)
7373
}
7474
return err
7575
}
@@ -110,7 +110,7 @@ func (hExService *HeaderExchangeService) Start() error {
110110
var err error
111111
// have to do the initializations here to utilize the p2p node which is created on start
112112
ps := hExService.p2p.PubSub()
113-
hExService.sub = goheaderp2p.NewSubscriber[*types.SignedHeader](ps, pubsub.DefaultMsgIdFn)
113+
hExService.sub = goheaderp2p.NewSubscriber[*types.SignedHeader](ps, pubsub.DefaultMsgIdFn, hExService.genesis.ChainID)
114114
if err = hExService.sub.Start(hExService.ctx); err != nil {
115115
return fmt.Errorf("error while starting subscriber: %w", err)
116116
}
@@ -131,7 +131,7 @@ func (hExService *HeaderExchangeService) Start() error {
131131
}
132132

133133
peerIDs := hExService.p2p.PeerIDs()
134-
if hExService.ex, err = newP2PExchange(hExService.p2p.Host(), peerIDs, network, hExService.p2p.ConnectionGater()); err != nil {
134+
if hExService.ex, err = newP2PExchange(hExService.p2p.Host(), peerIDs, network, hExService.genesis.ChainID, hExService.p2p.ConnectionGater()); err != nil {
135135
return err
136136
}
137137
if err = hExService.ex.Start(hExService.ctx); err != nil {
@@ -203,17 +203,24 @@ func newP2PServer(
203203
network string,
204204
opts ...goheaderp2p.Option[goheaderp2p.ServerParameters],
205205
) (*goheaderp2p.ExchangeServer[*types.SignedHeader], error) {
206-
return goheaderp2p.NewExchangeServer[*types.SignedHeader](host, store, network, opts...)
206+
opts = append(opts,
207+
goheaderp2p.WithNetworkID[goheaderp2p.ServerParameters](network),
208+
)
209+
return goheaderp2p.NewExchangeServer[*types.SignedHeader](host, store, opts...)
207210
}
208211

209212
func newP2PExchange(
210213
host host.Host,
211214
peers []peer.ID,
212-
network string,
215+
network, chainID string,
213216
conngater *conngater.BasicConnectionGater,
214217
opts ...goheaderp2p.Option[goheaderp2p.ClientParameters],
215218
) (*goheaderp2p.Exchange[*types.SignedHeader], error) {
216-
return goheaderp2p.NewExchange[*types.SignedHeader](host, peers, network, conngater, opts...)
219+
opts = append(opts,
220+
goheaderp2p.WithNetworkID[goheaderp2p.ClientParameters](network),
221+
goheaderp2p.WithChainID[goheaderp2p.ClientParameters](chainID),
222+
)
223+
return goheaderp2p.NewExchange[*types.SignedHeader](host, peers, conngater, opts...)
217224
}
218225

219226
// newSyncer constructs new Syncer for headers.
@@ -223,5 +230,5 @@ func newSyncer(
223230
sub header.Subscriber[*types.SignedHeader],
224231
opt goheadersync.Options,
225232
) (*sync.Syncer[*types.SignedHeader], error) {
226-
return sync.NewSyncer(ex, store, sub, opt)
233+
return sync.NewSyncer[*types.SignedHeader](ex, store, sub, opt)
227234
}

types/header.go

Lines changed: 16 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -75,60 +75,32 @@ func (h *Header) Time() time.Time {
7575
return time.Unix(int64(h.BaseHeader.Time), 0)
7676
}
7777

78-
func (h *Header) VerifyAdjacent(untrst header.Header) error {
78+
func (h *Header) Verify(untrst header.Header) error {
7979
untrstH, ok := untrst.(*Header)
8080
if !ok {
81-
return &header.VerifyError{
82-
Reason: fmt.Errorf("%T is not of type %T", untrst, h),
83-
}
84-
}
85-
86-
if untrstH.Height() != h.Height()+1 {
87-
return &header.VerifyError{
88-
Reason: fmt.Errorf("headers must be adjacent in height: trusted %d, untrusted %d", h.Height(), untrstH.Height()),
89-
}
81+
// if the header type is wrong, something very bad is going on
82+
// and is a programmer bug
83+
panic(fmt.Errorf("%T is not of type %T", untrst, h))
9084
}
91-
85+
// sanity check fields
9286
if err := verifyNewHeaderAndVals(h, untrstH); err != nil {
9387
return &header.VerifyError{Reason: err}
9488
}
95-
96-
// Check the validator hashes are the same
97-
// TODO: next validator set is not available
98-
if !bytes.Equal(untrstH.AggregatorsHash[:], h.AggregatorsHash[:]) {
99-
return &header.VerifyError{
100-
Reason: fmt.Errorf("expected old header next validators (%X) to match those from new header (%X)",
101-
h.AggregatorsHash,
102-
untrstH.AggregatorsHash,
103-
),
104-
}
105-
}
106-
107-
return nil
108-
109-
}
110-
111-
func (h *Header) VerifyNonAdjacent(untrst header.Header) error {
112-
untrstH, ok := untrst.(*Header)
113-
if !ok {
114-
return &header.VerifyError{
115-
Reason: fmt.Errorf("%T is not of type %T", untrst, h),
116-
}
117-
}
89+
// perform actual verification
11890
if untrstH.Height() == h.Height()+1 {
119-
return &header.VerifyError{
120-
Reason: fmt.Errorf(
121-
"headers must be non adjacent in height: trusted %d, untrusted %d",
122-
h.Height(),
123-
untrstH.Height(),
124-
),
91+
// Check the validator hashes are the same in the case headers are adjacent
92+
// TODO: next validator set is not available
93+
if !bytes.Equal(untrstH.AggregatorsHash[:], h.AggregatorsHash[:]) {
94+
return &header.VerifyError{
95+
Reason: fmt.Errorf("expected old header next validators (%X) to match those from new header (%X)",
96+
h.AggregatorsHash,
97+
untrstH.AggregatorsHash,
98+
),
99+
}
125100
}
126101
}
127102

128-
if err := verifyNewHeaderAndVals(h, untrstH); err != nil {
129-
return &header.VerifyError{Reason: err}
130-
}
131-
103+
// TODO: There must be a way to verify non-adjacent headers
132104
// Ensure that untrusted commit has enough of trusted commit's power.
133105
// err := h.ValidatorSet.VerifyCommitLightTrusting(eh.ChainID, untrst.Commit, light.DefaultTrustLevel)
134106
// if err != nil {

types/signed_header.go

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,15 @@ func (sH *SignedHeader) IsZero() bool {
1414
return sH == nil
1515
}
1616

17-
func (sH *SignedHeader) VerifyAdjacent(untrst header.Header) error {
17+
func (sH *SignedHeader) Verify(untrst header.Header) error {
1818
// Explicit type checks are required due to embedded Header which also does the explicit type check
1919
untrstH, ok := untrst.(*SignedHeader)
2020
if !ok {
21-
return &header.VerifyError{
22-
Reason: fmt.Errorf("%T is not of type %T", untrst, sH),
23-
}
21+
// if the header type is wrong, something very bad is going on
22+
// and is a programmer bug
23+
panic(fmt.Errorf("%T is not of type %T", untrst, untrstH))
2424
}
25-
return sH.Header.VerifyAdjacent(&untrstH.Header)
25+
return sH.Header.Verify(&untrstH.Header)
2626
}
2727

28-
func (sH *SignedHeader) VerifyNonAdjacent(untrst header.Header) error {
29-
untrstH, ok := untrst.(*SignedHeader)
30-
if !ok {
31-
return &header.VerifyError{
32-
Reason: fmt.Errorf("%T is not of type %T", untrst, sH),
33-
}
34-
}
35-
return sH.Header.VerifyNonAdjacent(&untrstH.Header)
36-
}
28+
var _ header.Header = &SignedHeader{}

0 commit comments

Comments
 (0)