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

Implement rhp4 basic client and server #96

Merged
merged 75 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
aee1098
rhp4: implement rhp4 server and basic client
n8maninger Sep 13, 2024
ca55d0f
deps: update core
n8maninger Sep 13, 2024
2ea0695
deps: remove replace directive
n8maninger Sep 13, 2024
570b9fb
rhp4: combine client and server packages
n8maninger Sep 13, 2024
d2cc526
rhp4: minify form and renew RPC
n8maninger Sep 13, 2024
c36795c
rhp4: remove debug logging
n8maninger Sep 13, 2024
1ac1b5c
rhp4: fix lint
n8maninger Sep 13, 2024
bfb7aa0
chain: extend test, add panic to encode functions
n8maninger Sep 13, 2024
612ff08
chain: use larger length prefix
n8maninger Sep 13, 2024
2d36531
rhp4: check offset is a multiple of LeafSize
n8maninger Sep 13, 2024
c0236b2
rhp4: add context to client methods
n8maninger Sep 13, 2024
ba11351
rhp4,testutil: fix mismatched muxes
n8maninger Sep 13, 2024
a1ae24b
deps: update mux
n8maninger Sep 13, 2024
b924d57
deps: update mux
n8maninger Sep 14, 2024
e76f65d
rhp/v4: Option->ServerOption
n8maninger Sep 17, 2024
9fbe148
rhp/v4: add basis diff comment
n8maninger Sep 17, 2024
5bed8f9
rhp/v4: address comments
n8maninger Sep 17, 2024
ec60cba
rhp/v4: address comments
n8maninger Sep 17, 2024
10ec12b
deps: update core and mux
n8maninger Sep 17, 2024
2bad9a0
implement basic sia mux client with context interupt
n8maninger Sep 17, 2024
cce2d6b
rhp/v4: RPC read sector write to writer
n8maninger Sep 17, 2024
a911c83
rhp/v4: use request validate
n8maninger Sep 19, 2024
46eb1e4
chain,rhp4: add type safe supported protocols
n8maninger Sep 26, 2024
d91a33d
rhp4: add invalid root error
n8maninger Sep 26, 2024
f7c5de1
rhp4: remove incremented revision number. It was moved to PayWithCont…
n8maninger Sep 26, 2024
6391156
rpc: move validate up
n8maninger Sep 27, 2024
161f86e
rhp4: add verify sector rpc
n8maninger Sep 27, 2024
8e75f20
Merge remote-tracking branch 'origin/master' into nate/rhp4
n8maninger Sep 27, 2024
24d8518
rho: add verify sector test
n8maninger Sep 27, 2024
e331259
Merge remote-tracking branch 'origin/master' into nate/rhp4
n8maninger Sep 27, 2024
cf28a22
rhp4: fix lint
n8maninger Sep 27, 2024
2e81244
rhp/v4: fix modify sectors test
n8maninger Sep 27, 2024
ab3a7bd
rhp4: add result types
n8maninger Sep 27, 2024
48da7a3
rhp4: address comments
n8maninger Sep 28, 2024
19326ed
rhp4: make input validation clearer
n8maninger Sep 28, 2024
4977cf4
rhp4,chain: remove slashes in protocol
n8maninger Sep 28, 2024
a80d6d9
rhp4: period in docstring
n8maninger Sep 28, 2024
9dc122d
rhp4: switch RPCWrite to streaming
n8maninger Sep 28, 2024
c1dddb9
rhp4: use clear for zero reader (Chris)
n8maninger Sep 28, 2024
3543c96
rhp4: add proof validation comment
n8maninger Sep 28, 2024
44117d3
rhp4: address review comments
n8maninger Sep 28, 2024
4592625
rhp4: add append sectors rpc
n8maninger Oct 2, 2024
aad5fd7
rhp4: fix lint
n8maninger Oct 2, 2024
1406d3d
rpc: set miner fee
n8maninger Oct 3, 2024
15e898d
rhp4,chain: simplify renew, move proof updates to chain manager (#102)
n8maninger Oct 8, 2024
c7e1c25
Merge branch 'master' into nate/rhp4
n8maninger Oct 8, 2024
56f89a2
rhp4 RPC Refresh (#104)
n8maninger Oct 8, 2024
e240c9c
rhp4: address comments
n8maninger Oct 8, 2024
a799184
deps: update core
n8maninger Oct 9, 2024
02dcd60
rhp/v4: Implement Merkle proofs
lukechampine Oct 10, 2024
322d7a3
rhp4: update interfaces
n8maninger Oct 19, 2024
da3e94e
rhp4: rename interface
n8maninger Oct 20, 2024
5a9fa81
rhp4: add UpgradeConn helper
n8maninger Oct 21, 2024
c00c7f7
Merge pull request #112 from SiaFoundation/nate/rhp4-upgrade-helper
n8maninger Oct 21, 2024
fac5183
rhp4: update frand
n8maninger Oct 22, 2024
9eb661e
Merge remote-tracking branch 'origin/master' into nate/rhp4
n8maninger Oct 22, 2024
17d2b72
chain: fix deadlock
n8maninger Oct 22, 2024
8bf8e6c
deps: update core
n8maninger Oct 21, 2024
c8966b7
rhp4: implement RPC remove
n8maninger Oct 21, 2024
b81a3e5
deps: upgrade core
n8maninger Oct 21, 2024
c14ef51
rhp4: use core usage
n8maninger Oct 21, 2024
37ab2f5
rhp4: add usage to form contract
n8maninger Oct 21, 2024
d816b0a
rhp4: RPC remove -> RPC free
n8maninger Oct 22, 2024
1a78cf7
Merge pull request #111 from SiaFoundation/nate/rhp4-rpc-remove
n8maninger Oct 23, 2024
50bdd90
deps: update core
n8maninger Oct 23, 2024
61581aa
rhp4: reduce test verbosity
n8maninger Oct 23, 2024
7e89429
rhp/v4: Fix failing Merkle proof tests
lukechampine Oct 24, 2024
288722c
Merge remote-tracking branch 'origin/master' into nate/rhp4
n8maninger Oct 24, 2024
1e5ac3f
deps: update core
n8maninger Oct 24, 2024
3f86f99
deps: update core
n8maninger Oct 24, 2024
f2fbcd6
rhp4: fix RPC refresh renter signatures
n8maninger Oct 24, 2024
2d0fd5b
reduce blocks mined for tests
n8maninger Oct 24, 2024
6741532
chain: explicit return values
n8maninger Oct 25, 2024
1d05f0a
rhp4: sector pointer
n8maninger Oct 26, 2024
5a00184
deps: update core
n8maninger Oct 28, 2024
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
12 changes: 6 additions & 6 deletions chain/chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,8 @@ func TestV2Attestations(t *testing.T) {
ms.Sync(t, cm)

sk := types.GeneratePrivateKey()
ann := chain.HostAnnouncement{
NetAddress: "foo.bar:1234",
ann := chain.V2HostAnnouncement{
chain.NetAddress{Address: "foo.bar:1234", Protocol: "tcp"},
}
se := ms.SpendableElement(t)
txn := types.V2Transaction{
Expand Down Expand Up @@ -232,8 +232,8 @@ func TestV2Attestations(t *testing.T) {
ms.Sync(t, cm)

sk := types.GeneratePrivateKey()
ann := chain.HostAnnouncement{
NetAddress: "foo.bar:1234",
ann := chain.V2HostAnnouncement{
chain.NetAddress{Address: "foo.bar:1234", Protocol: "tcp"},
}
txn := types.V2Transaction{
ArbitraryData: frand.Bytes(16),
Expand Down Expand Up @@ -276,8 +276,8 @@ func TestV2Attestations(t *testing.T) {
ms.Sync(t, cm)

sk := types.GeneratePrivateKey()
ann := chain.HostAnnouncement{
NetAddress: "foo.bar:1234",
ann := chain.V2HostAnnouncement{
chain.NetAddress{Address: "foo.bar:1234", Protocol: "tcp"},
}
se := ms.SpendableElement(t)
minerFee := types.Siacoins(1)
Expand Down
57 changes: 45 additions & 12 deletions chain/hostannouncement.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package chain

import (
"bytes"
"errors"

"go.sia.tech/core/consensus"
"go.sia.tech/core/types"
Expand All @@ -12,29 +13,57 @@ const attestationHostAnnouncement = "HostAnnouncement"
var specifierHostAnnouncement = types.NewSpecifier("HostAnnouncement")

// A HostAnnouncement represents a signed announcement of a host's network
// address. Announcements may be made via arbitrary data (in a v1 transaction)
// or via attestation (in a v2 transaction).
type HostAnnouncement struct {
NetAddress string
// address. Announcements may be made via arbitrary data
type (
HostAnnouncement struct {
NetAddress string
}

// A NetAddress is a pair of protocol and address that a host may be reached on
NetAddress struct {
Protocol string `json:"protocol"`
n8maninger marked this conversation as resolved.
Show resolved Hide resolved
Address string `json:"address"`
}

// A V2HostAnnouncement lists all the network addresses a host may be reached on
V2HostAnnouncement []NetAddress
n8maninger marked this conversation as resolved.
Show resolved Hide resolved
)

// EncodeTo implements types.EncoderTo.
func (na NetAddress) EncodeTo(e *types.Encoder) {
e.WriteString(na.Protocol)
e.WriteString(na.Address)
}

// DecodeFrom implements types.DecoderFrom.
func (na *NetAddress) DecodeFrom(d *types.Decoder) {
na.Protocol = d.ReadString()
na.Address = d.ReadString()
}

// ToAttestation encodes a host announcement as an attestation.
func (ha HostAnnouncement) ToAttestation(cs consensus.State, sk types.PrivateKey) types.Attestation {
func (ha V2HostAnnouncement) ToAttestation(cs consensus.State, sk types.PrivateKey) types.Attestation {
buf := bytes.NewBuffer(nil)
e := types.NewEncoder(buf)
types.EncodeSlice(e, ha)
e.Flush()
n8maninger marked this conversation as resolved.
Show resolved Hide resolved
a := types.Attestation{
PublicKey: sk.PublicKey(),
Key: attestationHostAnnouncement,
Value: []byte(ha.NetAddress),
Value: buf.Bytes(),
}
a.Signature = sk.SignHash(cs.AttestationSigHash(a))
return a
}

func (ha *HostAnnouncement) fromAttestation(a types.Attestation) bool {
// FromAttestation decodes a host announcement from an attestation.
func (ha *V2HostAnnouncement) FromAttestation(a types.Attestation) error {
if a.Key != attestationHostAnnouncement {
return false
return errors.New("not a host announcement")
}
ha.NetAddress = string(a.Value)
return true
d := types.NewBufDecoder(a.Value)
types.DecodeSlice(d, (*[]NetAddress)(ha))
lukechampine marked this conversation as resolved.
Show resolved Hide resolved
return d.Err()
}

// ToArbitraryData encodes a host announcement as arbitrary data.
Expand Down Expand Up @@ -81,10 +110,14 @@ func ForEachHostAnnouncement(b types.Block, fn func(types.PublicKey, HostAnnounc
}
}
}
}

// ForEachV2HostAnnouncement calls fn on each v2 host announcement in a block.
func ForEachV2HostAnnouncement(b types.Block, fn func(types.PublicKey, []NetAddress)) {
for _, txn := range b.V2Transactions() {
for _, a := range txn.Attestations {
var ha HostAnnouncement
if ha.fromAttestation(a) {
var ha V2HostAnnouncement
if err := ha.FromAttestation(a); err == nil {
fn(a.PublicKey, ha)
}
}
Expand Down
30 changes: 27 additions & 3 deletions chain/hostannouncement_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,41 @@ func TestForEachHostAnnouncement(t *testing.T) {
Transactions: []types.Transaction{
{ArbitraryData: [][]byte{ha.ToArbitraryData(sk)}},
},
}
ForEachHostAnnouncement(b, func(pk types.PublicKey, a HostAnnouncement) {
if pk != sk.PublicKey() {
t.Error("pubkey mismatch")
} else if a.NetAddress != ha.NetAddress {
t.Error("address mismatch:", a, ha)
}
})
}

func TestForEachV2HostAnnouncement(t *testing.T) {
sk := types.GeneratePrivateKey()
ha := V2HostAnnouncement([]NetAddress{
{Protocol: "tcp", Address: "foo.bar:1234"},
{Protocol: "tcp6", Address: "baz.qux:5678"},
{Protocol: "webtransport", Address: "quux.corge:91011"},
})
b := types.Block{
V2: &types.V2BlockData{
Transactions: []types.V2Transaction{
{Attestations: []types.Attestation{ha.ToAttestation(consensus.State{}, sk)}},
n8maninger marked this conversation as resolved.
Show resolved Hide resolved
},
},
}
ForEachHostAnnouncement(b, func(pk types.PublicKey, a HostAnnouncement) {
ForEachV2HostAnnouncement(b, func(pk types.PublicKey, addresses []NetAddress) {
if pk != sk.PublicKey() {
t.Error("pubkey mismatch")
} else if a.NetAddress != ha.NetAddress {
t.Error("address mismatch:", a, ha)
} else if len(addresses) != len(ha) {
t.Error("length mismatch")
} else {
for i := range addresses {
if addresses[i] != ha[i] {
t.Error("address mismatch:", addresses[i], ha[i])
}
}
}
})
}
2 changes: 1 addition & 1 deletion chain/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -941,7 +941,7 @@ func (m *Manager) UnconfirmedParents(txn types.Transaction) []types.Transaction

// V2TransactionSet returns the full transaction set and basis necessary for
// broadcasting a transaction. If the provided basis does not match the current
// tip the transaction will be updated. The transaction set includes the parents
// tip, the transaction will be updated. The transaction set includes the parents
// and the transaction itself in an order valid for broadcasting.
func (m *Manager) V2TransactionSet(basis types.ChainIndex, txn types.V2Transaction) (types.ChainIndex, []types.V2Transaction, error) {
m.mu.Lock()
Expand Down
8 changes: 3 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
module go.sia.tech/coreutils

go 1.22

toolchain go1.23.0
go 1.23.0

require (
go.etcd.io/bbolt v1.3.11
go.sia.tech/core v0.4.6
go.sia.tech/core v0.4.7-0.20240913032406-5d2eef629ec8
go.sia.tech/mux v1.2.0
go.uber.org/zap v1.27.0
golang.org/x/crypto v0.27.0
lukechampine.com/frand v1.4.2
)

require (
github.com/aead/chacha20 v0.0.0-20180709150244-8b13a72661da // indirect
go.sia.tech/mux v1.2.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/sys v0.25.0 // indirect
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKs
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
go.etcd.io/bbolt v1.3.11 h1:yGEzV1wPz2yVCLsD8ZAiGHhHVlczyC9d1rP43/VCRJ0=
go.etcd.io/bbolt v1.3.11/go.mod h1:dksAq7YMXoljX0xu6VF5DMZGbhYYoLUalEiSySYAS4I=
go.sia.tech/core v0.4.6 h1:QLm97a7GWBonfnMEOokqWRAqsWCUPL7kzo6k3Adwx8E=
go.sia.tech/core v0.4.6/go.mod h1:Zuq0Tn2aIXJyO0bjGu8cMeVWe+vwQnUfZhG1LCmjD5c=
go.sia.tech/core v0.4.7-0.20240913032406-5d2eef629ec8 h1:/5tKdGNBVm4lt5I/ta0C8I0Br9Pvi/hlvDbDja4IZLo=
go.sia.tech/core v0.4.7-0.20240913032406-5d2eef629ec8/go.mod h1:S7IRFqUy/vo2+oPtDq/o4rlAegNyoYQ7TWqsulE9R+w=
go.sia.tech/mux v1.2.0 h1:ofa1Us9mdymBbGMY2XH/lSpY8itFsKIo/Aq8zwe+GHU=
go.sia.tech/mux v1.2.0/go.mod h1:Yyo6wZelOYTyvrHmJZ6aQfRoer3o4xyKQ4NmQLJrBSo=
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
Expand Down
32 changes: 32 additions & 0 deletions rhp/v4/options.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package rhp

import (
"time"

"go.uber.org/zap"
)

// An Option sets an option on a Server.
type Option func(*Server)
n8maninger marked this conversation as resolved.
Show resolved Hide resolved

// WithLog sets the logger for the server.
func WithLog(log *zap.Logger) Option {
return func(s *Server) {
s.log = log
}
}

// WithPriceTableValidity sets the duration for which a price table is valid.
func WithPriceTableValidity(validity time.Duration) Option {
return func(s *Server) {
s.priceTableValidity = validity
}
}

// WithContractProofWindowBuffer sets the buffer for revising a contract before
// its proof window starts.
func WithContractProofWindowBuffer(buffer uint64) Option {
return func(s *Server) {
s.contractProofWindowBuffer = buffer
}
}
Loading
Loading