Skip to content

Commit

Permalink
Merge pull request #130 from relab/bugfix/issue129
Browse files Browse the repository at this point in the history
Fix TimeoutMsgFromProto reported in issue 129
  • Loading branch information
meling authored Dec 17, 2024
2 parents 30f3f22 + 1b5c3ff commit ecadd95
Show file tree
Hide file tree
Showing 12 changed files with 79 additions and 36 deletions.
8 changes: 8 additions & 0 deletions .vscode/dict.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,23 @@ Bano
Baudet
BFT's
Bitfield
bitmask
cerr
chainedhotstuff
checkf
Chursin
clientpb
cmdqueue
Cmds
cmpopts
CODECOV
covermode
coverpkg
coverprofile
cpuprofile
Debugf
durationpb
dylib
eddsa
emptypb
Erevik
Expand All @@ -28,6 +31,7 @@ Feng
ferr
fgprof
fgprofprofile
gcflags
gocyclo
golangci
golint
Expand All @@ -36,6 +40,7 @@ gorums
gpool
grpc
Gueta
handelpb
Hein
hostnames
HOTSTUFF
Expand All @@ -44,13 +49,15 @@ hotstuffpb
iagotest
ICDCS
iface
Iinternal
Infof
Jalalzai
Jehl
Jianyu
keygen
kilic
latencygen
ldflags
leaderrotation
Malkhi
Mathieu
Expand All @@ -72,6 +79,7 @@ propsed
proto
protobuf
protoc
protos
protostream
ptypes
QC's
Expand Down
14 changes: 13 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,17 @@
"go.testFlags": [
"-count=1"
],
"cSpell.enabled": true
"cSpell.enabled": true,
"cSpell.ignorePaths": [
"package-lock.json",
"node_modules",
"vscode-extension",
".git/{info,lfs,logs,refs,objects}/**",
".git/{index,*refs,*HEAD}",
".vscode",
".vscode-insiders",
"go.mod",
"go.sum",
"**/**/*.pb.go"
]
}
2 changes: 1 addition & 1 deletion crypto/bls12/bls12.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ func (bls *bls12Base) fastAggregateVerify(publicKeys []*PublicKey, message []byt
return bls.coreVerify(&PublicKey{p: &aggregate}, message, signature, domain)
}

// Sign creates a cryptographic signature of the given messsage.
// Sign creates a cryptographic signature of the given message.
func (bls *bls12Base) Sign(message []byte) (signature hotstuff.QuorumSignature, err error) {
p, err := bls.coreSign(message, domain)
if err != nil {
Expand Down
20 changes: 10 additions & 10 deletions docs/experimentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -235,19 +235,19 @@ these additional flags are used:
- `--worker` runs a worker locally, in addition to the remote hosts specified. Use this if you want the local machine
to participate in the experiment.

Additionally, it is possible to specify an *internal address* for each host.
Additionally, it is possible to specify an _internal address_ for each host.
The internal address is used by replicas instead of the address used by the controller.
This is useful if the controller is connecting to the remote hosts using a global address,
whereas the hosts can communicate using local addresses.
The internal address is configured through the configuration file (loaded by the `--config` flag):

```toml
[[hosts-config]]
name = "hotstuff_worker_1"
name = "hotstuff-worker-1"
internal-address = "192.168.10.2"

[[hosts-config]]
name = "hotstuff_worker_1"
name = "hotstuff-worker-1"
internal-address = "192.168.10.3"
```

Expand All @@ -262,21 +262,21 @@ The following shows a configuration file that customizes the client and replica
clients = 2
replicas = 8

hosts = [
"hotstuff_worker_1",
"hotstuff_worker_2",
"hotstuff_worker_3",
"hotstuff_worker_4",
hosts = [
"hotstuff-worker-1",
"hotstuff-worker-2",
"hotstuff-worker-3",
"hotstuff-worker-4",
]

# specific assignments for some hosts
[[hosts-config]]
name = "hotstuff_worker_1"
name = "hotstuff-worker-1"
clients = 2
replicas = 0
```

In particular, in this example the host named `hotstuff_worker_1` is configured to run both clients and no replicas.
In particular, in this example the host named `hotstuff-worker-1` is configured to run both clients and no replicas.
The remaining replicas are divided among the remaining hosts. If all hosts are manually configured, the total number of
clients and replicas configured must equal the requested number of clients and replicas.

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ require (
github.com/felixge/fgprof v0.9.4
github.com/golang/mock v1.6.0
github.com/golang/protobuf v1.5.4
github.com/google/go-cmp v0.6.0
github.com/kilic/bls12-381 v0.1.1-0.20210208205449-6045b0235e36
github.com/mattn/go-isatty v0.0.20
github.com/mitchellh/go-homedir v1.1.0
Expand Down Expand Up @@ -46,7 +47,6 @@ require (
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect
github.com/gonuts/binary v0.2.0 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/pprof v0.0.0-20240227163752-401108e1b7e7 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
Expand Down
2 changes: 1 addition & 1 deletion internal/proto/hotstuffpb/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func TimeoutMsgFromProto(m *TimeoutMsg) hotstuff.TimeoutMsg {
SyncInfo: SyncInfoFromProto(m.GetSyncInfo()),
ViewSignature: QuorumSignatureFromProto(m.GetViewSig()),
}
if m.GetViewSig() != nil {
if m.GetMsgSig() != nil {
timeoutMsg.MsgSignature = QuorumSignatureFromProto(m.GetMsgSig())
}
return timeoutMsg
Expand Down
26 changes: 26 additions & 0 deletions internal/proto/hotstuffpb/convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"bytes"
"testing"

"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/relab/hotstuff"
"github.com/relab/hotstuff/modules"

Expand Down Expand Up @@ -95,3 +97,27 @@ func TestConvertTimeoutCertBLS12(t *testing.T) {
t.Fatal("Failed to verify timeout cert")
}
}

func TestTimeoutMsgFromProto_Issue129(t *testing.T) {
sig := &QuorumSignature{Sig: &QuorumSignature_ECDSASigs{ECDSASigs: &ECDSAMultiSignature{Sigs: []*ECDSASignature{}}}}
sync := &SyncInfo{QC: &QuorumCert{Sig: sig, Hash: []byte{1, 2, 3, 4}}}

tests := []struct {
name string
msg *TimeoutMsg
want hotstuff.TimeoutMsg
}{
{name: "only-view", msg: &TimeoutMsg{View: 1}, want: hotstuff.TimeoutMsg{View: 1}},
{name: "only-sync-info", msg: &TimeoutMsg{SyncInfo: sync}, want: hotstuff.TimeoutMsg{SyncInfo: SyncInfoFromProto(sync)}},
{name: "only-msg-signature", msg: &TimeoutMsg{MsgSig: sig}, want: hotstuff.TimeoutMsg{MsgSignature: QuorumSignatureFromProto(sig)}},
{name: "only-view-signature", msg: &TimeoutMsg{ViewSig: sig}, want: hotstuff.TimeoutMsg{ViewSignature: QuorumSignatureFromProto(sig)}},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := TimeoutMsgFromProto(tt.msg)
if diff := cmp.Diff(tt.want, got, cmpopts.IgnoreUnexported(hotstuff.SyncInfo{})); diff != "" {
t.Errorf("TimeoutMsgFromProto() mismatch (-want +got):\n%s", diff)
}
})
}
}
15 changes: 7 additions & 8 deletions scripts/deploy_test.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

join () {
join() {
local IFS="$1"
shift
echo "$*"
Expand All @@ -10,23 +10,22 @@ num_hosts=4

declare -A hosts

for ((i=1; i<=num_hosts; i++)); do
hosts[$i]="hotstuff_worker_$i"
for ((i = 1; i <= num_hosts; i++)); do
hosts[$i]="hotstuff-worker-$i"
done


if [ ! -f "./id" ]; then
ssh-keygen -t ed25519 -C "hotstuff-test" -f "./id" -N ""
fi

compose_args="--project-name=hotstuff"

docker-compose $compose_args up -d --build --scale worker=4
docker compose $compose_args up -d --build --scale worker=4

docker-compose $compose_args exec -T controller /bin/sh -c "ssh-keyscan -H $(join ' ' "${hosts[@]}") >> ~/.ssh/known_hosts" &>/dev/null
docker-compose $compose_args exec -T controller /bin/sh -c "hotstuff run --hosts '$(join ',' "${hosts[@]}")' --config ./example_config.toml --log-level info"
docker compose $compose_args exec -T controller /bin/sh -c "ssh-keyscan -H $(join ' ' "${hosts[@]}") >> ~/.ssh/known_hosts" &>/dev/null
docker compose $compose_args exec -T controller /bin/sh -c "hotstuff run --hosts '$(join ',' "${hosts[@]}")' --config ./example_config.toml --log-level info"
exit_code="$?"

docker-compose $compose_args down
docker compose $compose_args down

exit $exit_code
2 changes: 0 additions & 2 deletions scripts/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: '3.8'

services:
worker:
build:
Expand Down
14 changes: 7 additions & 7 deletions scripts/example_config.toml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
clients = 2
replicas = 8

hosts = [
"hotstuff_worker_1",
"hotstuff_worker_2",
"hotstuff_worker_3",
"hotstuff_worker_4",
hosts = [
"hotstuff-worker-1",
"hotstuff-worker-2",
"hotstuff-worker-3",
"hotstuff-worker-4",
]

# specific assingments for some hosts
# specific assignments for some hosts
[[hosts-config]]
name = "hotstuff_worker_1"
name = "hotstuff-worker-1"
clients = 2
replicas = 0
8 changes: 4 additions & 4 deletions scripts/single_worker.sh
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
#!/bin/bash

image="hotstuff_worker"
image="hotstuff-worker"

if [ ! -f "./id" ]; then
ssh-keygen -t ed25519 -C "hotstuff-test" -f "./id" -N ""
fi

# ensure that the image is built
docker images | grep "$image" &>/dev/null \
|| docker build -t "$image" -f "./Dockerfile.worker" ".."
docker images | grep "$image" &>/dev/null ||
docker build -t "$image" -f "./Dockerfile.worker" ".."

container="$(docker run --rm -d -p 2020:22 -p 4000:4000 "$image")"

sleep 1s

ssh-keyscan -p 2020 127.0.0.1 localhost > known_hosts
ssh-keyscan -p 2020 127.0.0.1 localhost >known_hosts

docker logs --follow "$container"
docker rm -f "$container" &>/dev/null
2 changes: 1 addition & 1 deletion scripts/ssh_config
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# ssh_config used with the controller container

Host hotstuff_worker_*
Host hotstuff-worker-*
User root
IdentityFile ~/.ssh/id

0 comments on commit ecadd95

Please sign in to comment.