Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
156 commits
Select commit Hold shift + click to select a range
2e49221
Some struct field name changes in core.go and a type reflection schem…
AlanRostem Jun 6, 2024
7fe8655
Test case for AddPipelined(), but it is incomplete. Passes without an…
AlanRostem Jun 6, 2024
6cd47f1
Pipelined module test considers multiple modules. Still incomplete, b…
AlanRostem Jun 7, 2024
75aa424
Added a type check to AddPipelined in core.go
AlanRostem Jun 10, 2024
4a12276
Testing out a new pipelined module creation scheme
AlanRostem Jun 10, 2024
11b9792
Builder now builds pipelined modules to Core. All tests pass without …
AlanRostem Jun 10, 2024
d18e7e2
Test case for module pipelines done
AlanRostem Jun 11, 2024
2110d11
Fixed a bug in multiplier test
AlanRostem Jun 11, 2024
567c3e0
Created a TryGet for pipelined modules which do something similar but…
AlanRostem Jun 17, 2024
b07cb00
Bug in TryGetPipelined fixed where nil value check was inverted. Adde…
AlanRostem Jun 17, 2024
8b0fe92
Code cleanup and additional documentation
AlanRostem Jun 17, 2024
5f302d0
Added helpers to enable creating pipelines from ids specified by the …
AlanRostem Jun 17, 2024
8081129
Changed function naming to minimize needed refactorings. Added commen…
AlanRostem Jun 19, 2024
014d4f8
Fixed a potential bug in builder.Build(). Corrections to error messag…
AlanRostem Jun 19, 2024
d66dc23
Renamed the pipelined get functions in core.go
AlanRostem Jul 2, 2024
d84daed
Separated pipeline ID type and constants to another go-module so that…
AlanRostem Jul 8, 2024
47f4057
Created a separate pipelined event loop to avoid code refactorings. T…
AlanRostem Jul 9, 2024
4f83a51
Pipelined eventloop passes the same type of tests as the regular one.…
AlanRostem Jul 10, 2024
50572b0
Optimized pipelined eventloop maps that hold handlers and tickers
AlanRostem Jul 11, 2024
5a11a2b
Added standard function versions to PipelinedEventLoop. Next step is …
AlanRostem Jul 12, 2024
9744f29
New branch for network-related pipelining integration.
AlanRostem Aug 27, 2024
1fb2afe
Eventloop supporting pipelining integrated to all of the code.
AlanRostem Aug 27, 2024
bb15725
Experimental RPC for pipelined proposals only
AlanRostem Aug 27, 2024
3fcb234
Refactoring words like 'pipelined' to 'piped'. ProposePiped reverted …
AlanRostem Aug 27, 2024
70cdf51
Remaining refactoring from previous commit
AlanRostem Aug 27, 2024
2dba180
Got a new RPC to work
AlanRostem Aug 28, 2024
2647ebf
Remaining rpcs added. Need to change eventloop again
AlanRostem Aug 29, 2024
8370b37
Refined the eventloop's pipelining capabilities. Some validation adde…
AlanRostem Aug 30, 2024
8bcfc9f
Merge pull request #1 from AlanRostem/network-pipelining
AlanRostem Aug 30, 2024
90a6f54
Cleaner pipelining in eventloop. InitModule takes in a pipeId now.
AlanRostem Aug 30, 2024
8e7a152
Simplified pipeID for RPC and all InitModules take a pipeId
AlanRostem Sep 2, 2024
8e3ede8
InitModule has BuildOptions as extram param, including pipeId and add…
AlanRostem Sep 2, 2024
e7056e4
Separated TestPropose to TestProposePiped in backend_test.go. Propose…
AlanRostem Sep 3, 2024
5cd1def
Timeout does PipeEvent
AlanRostem Sep 4, 2024
818aa70
Core and Builder bugs fixed and now they support adding objects not o…
AlanRostem Sep 4, 2024
2829603
Small changes
AlanRostem Sep 4, 2024
2cd4fd2
Reverted consensus_test.go changes
AlanRostem Sep 4, 2024
2a6a75b
Fixed a critical bug causing voting machine to not start
AlanRostem Sep 5, 2024
52f7f5e
Blocks have pipe now. Tested and works
AlanRostem Sep 5, 2024
6e6103d
Blocks have pipe ID and its hash accommodates this new field
AlanRostem Sep 5, 2024
d7d8c07
Piped blockchain proof-of-concept code.
AlanRostem Sep 6, 2024
ed364c2
Trying out a pipelined blockchain algorithm. Need to write tests somehow
AlanRostem Sep 9, 2024
1848c9a
Pipelining applied to module implementations in backend_test.go
AlanRostem Sep 10, 2024
e05695a
Major changes to modules, tests cases and test utilities to support p…
AlanRostem Sep 10, 2024
0da79cd
Deleted non-functioning tests. Moving commit logic from consensus to …
AlanRostem Sep 11, 2024
732ac9a
Attempt at fixing error from last commit. Made new module BlockCompos…
AlanRostem Sep 12, 2024
691b7c8
Bug fixes, but tests still fail.
AlanRostem Sep 12, 2024
c6ba2d8
Bug discovered though adding BlockCompositor to old version of hotstu…
AlanRostem Sep 12, 2024
7e107b8
Renamed the new module. New block pruning algorithm proposal for pipe…
AlanRostem Sep 13, 2024
8105fae
Changed name of new module
AlanRostem Sep 16, 2024
52d831e
Pruning algorithm changed, but the tests still fail...
AlanRostem Sep 17, 2024
643fbe3
Code works more like it used to
AlanRostem Sep 18, 2024
d081674
Preparing code for piped committing
AlanRostem Sep 18, 2024
1fe064f
Piped committer added, but missing fork handling. An attempt at creat…
AlanRostem Sep 19, 2024
fda9ee5
Got binary to run, but pipes are not considered when creating a block.
AlanRostem Sep 23, 2024
6599f7d
Pipe usage in QuorumCert. Need to use it in other message types.
AlanRostem Sep 24, 2024
838aefb
Pipe added to message convertion where it's needed. Some functionalit…
AlanRostem Sep 24, 2024
05b14ba
Piped modules send events to pipes now. Need to debug why the blocks …
AlanRostem Sep 24, 2024
8aea81c
Squashed bugs in server.go and crypto.go where wrong pipes were suppl…
AlanRostem Sep 25, 2024
e7e9165
Fixed a bug where InitModule did not receive pipe count in non-piped …
AlanRostem Sep 25, 2024
0c02f5c
Pushing large codebase changes with bugs.
AlanRostem Sep 26, 2024
96494b2
Bugs fixed. Need to do further investigation of incorrect pipe usage …
AlanRostem Sep 26, 2024
4954591
Pipelining only requires a pipe count to be enabled.
AlanRostem Sep 27, 2024
88f4108
Bugs fixed in eventloop causing piped modules to respond to incorrect…
AlanRostem Sep 27, 2024
d00829e
Pipelining ordering implemented. Works with a few incorrections.
AlanRostem Sep 27, 2024
8f59da6
Minor bug fixes to piped committer and error handling.
AlanRostem Sep 27, 2024
be2cb4f
Small code cleanup.
AlanRostem Sep 27, 2024
0f9b3ec
Prototype fork handling.
AlanRostem Sep 30, 2024
d827a97
Debug logs added to pipedCommiter
AlanRostem Oct 2, 2024
9852a4b
Added a bug fix to duplicate in queue piped committer queue
AlanRostem Oct 2, 2024
56973cc
Log file cleanup. Comments cleaned up in piped committer
AlanRostem Oct 3, 2024
ab369c9
Added extra debug statements for consensus and execution related code.
AlanRostem Oct 3, 2024
3662e21
Made a logging script that I can use quickly
AlanRostem Oct 4, 2024
2fb147c
Fixed a bug where an event was piped where it should not have been
AlanRostem Oct 7, 2024
a4c16ba
Tested and fixed bugs with timeout contexts. Found out that the commi…
AlanRostem Oct 8, 2024
506d0ba
Log file cleanup.
AlanRostem Oct 8, 2024
7dbf89c
WIP unordered committer for testing throughput.
AlanRostem Oct 8, 2024
92cda2e
Removed largee log files.
AlanRostem Oct 8, 2024
d23f109
Ingoring log directory.
AlanRostem Oct 8, 2024
af7940c
Changed orchestration to support pipelining as a cli option.
AlanRostem Oct 8, 2024
8ec463f
Bug fix that would stop normal execution without pipelining.
AlanRostem Oct 8, 2024
87487f6
Small code cleanup.
AlanRostem Oct 8, 2024
a21bbbf
Can now change pipeline ordering in cli.
AlanRostem Oct 9, 2024
e99552a
Major bugfix to timeout and view-change contexts not cancelling on th…
AlanRostem Oct 9, 2024
8890661
Logging rejected command data. Seems that duplicates are indeed being…
AlanRostem Oct 9, 2024
f52403d
Trying a piped cmdCache method.
AlanRostem Oct 10, 2024
1aee2ef
Reverted cmdCache changes and added support for other consensus rules
AlanRostem Oct 22, 2024
f1d0cd6
Using hashing to assign marshalled commands to pipes accordingly. Per…
AlanRostem Oct 22, 2024
aabd2bb
Changed how commands are marked in consensus and added an error check…
AlanRostem Oct 22, 2024
d3b8def
Modified a logged running script and added back some piped cmdcache s…
AlanRostem Oct 22, 2024
cbdf67d
Fixed a mutex bug
AlanRostem Oct 22, 2024
8ca3c26
Made the module pipelining simpler
AlanRostem Oct 23, 2024
e906680
Fixed a crash during debugging commands.
AlanRostem Oct 23, 2024
b2a52bc
Name changes.
AlanRostem Oct 24, 2024
6ead478
Can now switch the different cmdCache input methods
AlanRostem Oct 24, 2024
3c1220d
Implemented throughput measurements on indivudual pipes
AlanRostem Oct 28, 2024
73b1b70
Added a debug metrics module for logging debug-related data
AlanRostem Oct 28, 2024
95b12d5
Fixed bug: halt event was not emitted on the correct line
AlanRostem Oct 28, 2024
f4335ae
Debug events added to eventloop. View duration is global for all pipe…
Oct 29, 2024
5659684
Can now specify whether or not to duplicate view duration states when…
AlanRostem Oct 30, 2024
871d6f9
Merge resolved.
AlanRostem Oct 30, 2024
fc1c4a9
Discovered a bug with viewduration duplication: it is never duplicate…
AlanRostem Oct 30, 2024
e3adcfb
Fixed the bug from last commit.
AlanRostem Oct 30, 2024
65a3ac4
Added debug package with debug events.
AlanRostem Oct 30, 2024
53750e6
Bug fix. Should now be able to log rejected commands.
AlanRostem Oct 30, 2024
b9385b1
Fixed a bug where the metrics would log to nil map.
AlanRostem Oct 30, 2024
b694f9e
Can now run with one pipe
AlanRostem Oct 30, 2024
9b105f7
Merge branch 'master' of github.com:AlanRostem/hotstuff-pipelined
AlanRostem Oct 30, 2024
c82f615
Fixed duration and fixed the DelayUntil bug in votingmachine.
AlanRostem Oct 30, 2024
27e18e0
Improved debug metric type.
AlanRostem Oct 31, 2024
51453ae
Merge conflict resolved
AlanRostem Oct 31, 2024
bcc7555
Tinkering and code cleaning. Found that views time out excessively on…
AlanRostem Oct 31, 2024
39f2197
Event loop bug fixes.
AlanRostem Oct 31, 2024
10c0702
Another bug in event loop fixed, though it seems to not change much.
AlanRostem Oct 31, 2024
7b8a8cf
Eventloop has become entirely piped to accomodate bugs.
AlanRostem Oct 31, 2024
15c4eeb
Put the commit halt debug event in correct spot and gonna measure it.
AlanRostem Oct 31, 2024
d46fb30
Added more details to debug logs in consensus and vm.
AlanRostem Nov 1, 2024
fbacb0e
Debug log bug fix.
AlanRostem Nov 1, 2024
ed4ef16
View is added to each debug line.
AlanRostem Nov 1, 2024
733775e
Debug line on vote.
AlanRostem Nov 1, 2024
86d6220
Fixing some synchronizer and context tests to check errors with pipel…
AlanRostem Nov 3, 2024
5af90e8
Committed a log which should be analyzed to detect the 3-pipe failures.
AlanRostem Nov 3, 2024
22081a1
Using deterministic marshaler for hashing commands into queues.
AlanRostem Nov 3, 2024
b559405
Implemented a more coherent way to do piped cmdCaches.
AlanRostem Nov 4, 2024
c21b7a6
Removed unordered piped committer.
AlanRostem Nov 4, 2024
0eeaac0
Using the sequence number to distributed command to a pipe. Works muc…
AlanRostem Nov 4, 2024
2e4a856
Printing server latency to check if simulated latency works in real s…
AlanRostem Nov 5, 2024
b168ecb
Cleaning up orchestration.
AlanRostem Nov 5, 2024
d87bfd5
Some file cleanups and old test fixes
AlanRostem Nov 7, 2024
5f06f3b
Merge branch 'master' of github.com:AlanRostem/hotstuff-pipelined
AlanRostem Nov 7, 2024
03435ed
Hacky latency induction is being done on a different goroutine.
AlanRostem Nov 7, 2024
8aef8c6
Rename committer modules and added them to their own package.
AlanRostem Nov 9, 2024
81b2358
Adding pipeline-awareness to some modules and added a few todo's
AlanRostem Nov 10, 2024
1cab647
Merge resolved.
AlanRostem Nov 10, 2024
75170ad
Forgot the rest of the server.go file.
AlanRostem Nov 10, 2024
32f6080
Renamed pipe value to instance and all references to pipe are renamed…
AlanRostem Nov 11, 2024
b84e616
Renaming pipes to instance in protobuf definitions.
AlanRostem Nov 11, 2024
6c96899
Rename RespondToPipe to RespondToInstance.
AlanRostem Nov 11, 2024
380be52
Removed junk files
AlanRostem Nov 11, 2024
3a55811
Renaming pipe -> scope
AlanRostem Nov 13, 2024
4c9824c
Bug occurs when using unscoped eventloop in client and measurements. …
AlanRostem Nov 13, 2024
6c4a401
Remaining name changes
AlanRostem Nov 13, 2024
6cf634a
Forgot to save this one file.
AlanRostem Nov 13, 2024
610d5e6
Cleaned up launch config and further renaming.
AlanRostem Nov 13, 2024
81c06a3
Using name multiplexed committer.
AlanRostem Nov 13, 2024
5a57a64
Further naming fixes.
AlanRostem Nov 16, 2024
2da2ad6
Rename InitOptions -> ScopeInfo
AlanRostem Nov 19, 2024
42d8198
Going back to using pipe as a name
AlanRostem Nov 21, 2024
554fb59
Committer rename
AlanRostem Nov 21, 2024
5f249ef
Rename more accurate
AlanRostem Nov 21, 2024
e8455e4
Slight rename to adding scoped modules.
AlanRostem Nov 22, 2024
3412bc8
Small name change to a variable in block.Bytes()
AlanRostem Nov 23, 2024
619ee52
Fixed bugs with creating fixed vs dynamic view duration
AlanRostem Nov 27, 2024
02c30ae
Forgot to fix one consensus test
AlanRostem Nov 29, 2024
0ab81a2
Disabled TLS to prevent a bug. Added debug lines to replica stopping …
AlanRostem Nov 29, 2024
ae4dccc
Update README.md
AlanRostem Dec 4, 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
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ __debug_bin
# binaries
/hotstuff
/plot

**/__debug_bin*

# other
*.in
Expand All @@ -35,3 +35,5 @@ measurements.json
*.pdf

twins.json

/debug_logs
4 changes: 2 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"program": "${workspaceRoot}/cmd/hotstuff/main.go",
"cwd": "${workspaceRoot}",
"args": [
"run"
"run",
]
},
{
Expand Down Expand Up @@ -55,4 +55,4 @@
"host": "127.0.0.1"
}
]
}
}
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# NOTICE

This implementation was done as part of Alan Rostem's master's thesis.

# hotstuff

[![Go Reference](https://pkg.go.dev/badge/github.com/relab/consensus.svg)](https://pkg.go.dev/github.com/relab/hotstuff)
Expand Down
104 changes: 98 additions & 6 deletions backend/backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,33 @@ func TestConnect(t *testing.T) {
runBoth(t, run)
}

// Mainly test initialization of scoped modules and how they depend on each other.
func TestConnectScoped(t *testing.T) {
run := func(t *testing.T, setup setupFunc) {
const n = 4
ctrl := gomock.NewController(t)
td := setup(t, ctrl, n)
builder := modules.NewBuilder(1, td.keys[0])
testutil.TestModulesScoped(t, ctrl, 1, td.keys[0], &builder, 4)
teardown := createServers(t, td, ctrl)
defer teardown()
td.builders.Build()

cfg := NewConfig(td.creds, gorums.WithDialTimeout(time.Second))

builder.Add(cfg)
builder.Build()

err := cfg.Connect(td.replicas)
if err != nil {
t.Error(err)
}
}
runBoth(t, run)
}

// testBase is a generic test for a unicast/multicast call
func testBase(t *testing.T, typ any, send func(modules.Configuration), handle eventloop.EventHandler) {
func testBase(t *testing.T, typ any, send func(modules.Configuration), handle eventloop.EventHandler, opts ...eventloop.HandlerOption) {
run := func(t *testing.T, setup setupFunc) {
const n = 4
ctrl := gomock.NewController(t)
Expand All @@ -69,11 +94,11 @@ func testBase(t *testing.T, typ any, send func(modules.Configuration), handle ev
ctx, cancel := context.WithCancel(context.Background())
for _, hs := range hl[1:] {
var (
eventLoop *eventloop.EventLoop
eventLoop *eventloop.ScopedEventLoop
synchronizer modules.Synchronizer
)
hs.Get(&eventLoop, &synchronizer)
eventLoop.RegisterHandler(typ, handle)
eventLoop.RegisterHandler(typ, handle, opts...)
synchronizer.Start(ctx)
go eventLoop.Run(ctx)
}
Expand All @@ -89,10 +114,16 @@ func TestPropose(t *testing.T) {
ID: 1,
Block: hotstuff.NewBlock(
hotstuff.GetGenesis().Hash(),
hotstuff.NewQuorumCert(nil, 0, hotstuff.GetGenesis().Hash()),
"foo", 1, 1,
hotstuff.NewQuorumCert(
nil,
0,
hotstuff.NullPipe, // TODO: Verify if this code conflicts with pipelining
hotstuff.GetGenesis().Hash()),
"foo", 1, 1, 0,
),
Pipe: 0,
}

testBase(t, want, func(cfg modules.Configuration) {
wg.Add(3)
cfg.Propose(want)
Expand All @@ -109,13 +140,47 @@ func TestPropose(t *testing.T) {
})
}

func TestProposeScoped(t *testing.T) {
var wg sync.WaitGroup
pipe := hotstuff.Pipe(123)
want := hotstuff.ProposeMsg{
ID: 1,
Block: hotstuff.NewBlock(
hotstuff.GetGenesis().Hash(),
hotstuff.NewQuorumCert(
nil,
0,
hotstuff.NullPipe, // TODO: Verify if this code conflicts with pipelining
hotstuff.GetGenesis().Hash()),
"foo", 1, 1, pipe,
),
Pipe: pipe,
}

testBase(t, want, func(cfg modules.Configuration) {
wg.Add(3)
cfg.Propose(want)
wg.Wait()
}, func(event any) {
got := event.(hotstuff.ProposeMsg)
if got.ID != want.ID {
t.Errorf("wrong id in proposal: got: %d, want: %d", got.ID, want.ID)
}
if got.Block.Hash() != want.Block.Hash() {

t.Errorf("block hashes do not match. want %d got %d", got.Block.Pipe(), want.Block.Pipe())
}
wg.Done()
}, eventloop.RespondToScope(pipe))
}

func TestTimeout(t *testing.T) {
var wg sync.WaitGroup
want := hotstuff.TimeoutMsg{
ID: 1,
View: 1,
ViewSignature: nil,
SyncInfo: hotstuff.NewSyncInfo(),
SyncInfo: hotstuff.NewSyncInfo(hotstuff.NullPipe),
}
testBase(t, want, func(cfg modules.Configuration) {
wg.Add(3)
Expand All @@ -133,6 +198,33 @@ func TestTimeout(t *testing.T) {
})
}

func TestTimeoutScoped(t *testing.T) {
var wg sync.WaitGroup

pipe := hotstuff.Pipe(1)
want := hotstuff.TimeoutMsg{
ID: 1,
View: 1,
ViewSignature: nil,
SyncInfo: hotstuff.NewSyncInfo(pipe),
Pipe: pipe,
}
testBase(t, want, func(cfg modules.Configuration) {
wg.Add(3)
cfg.Timeout(want)
wg.Wait()
}, func(event any) {
got := event.(hotstuff.TimeoutMsg)
if got.ID != want.ID {
t.Errorf("wrong id in proposal: got: %d, want: %d", got.ID, want.ID)
}
if got.View != want.View {
t.Errorf("wrong view in proposal: got: %d, want: %d", got.View, want.View)
}
wg.Done()
}, eventloop.RespondToScope(pipe))
}

type testData struct {
n int
creds credentials.TransportCredentials
Expand Down
14 changes: 7 additions & 7 deletions backend/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (

// Replica provides methods used by hotstuff to send messages to replicas.
type Replica struct {
eventLoop *eventloop.EventLoop
eventLoop *eventloop.ScopedEventLoop
node *hotstuffpb.Node
id hotstuff.ID
pubKey hotstuff.PublicKey
Expand All @@ -46,7 +46,7 @@ func (r *Replica) Vote(cert hotstuff.PartialCert) {
if r.node == nil {
return
}
ctx, cancel := synchronizer.TimeoutContext(r.eventLoop.Context(), r.eventLoop)
ctx, cancel := synchronizer.ScopedTimeoutContext(r.eventLoop.Context(), r.eventLoop, cert.Pipe())
defer cancel()
pCert := hotstuffpb.PartialCertToProto(cert)
r.node.Vote(ctx, pCert)
Expand All @@ -57,7 +57,7 @@ func (r *Replica) NewView(msg hotstuff.SyncInfo) {
if r.node == nil {
return
}
ctx, cancel := synchronizer.TimeoutContext(r.eventLoop.Context(), r.eventLoop)
ctx, cancel := synchronizer.ScopedTimeoutContext(r.eventLoop.Context(), r.eventLoop, msg.Pipe())
defer cancel()
r.node.NewView(ctx, hotstuffpb.SyncInfoToProto(msg))
}
Expand All @@ -78,7 +78,7 @@ type Config struct {
}

type subConfig struct {
eventLoop *eventloop.EventLoop
eventLoop *eventloop.ScopedEventLoop
logger logging.Logger
opts *modules.Options

Expand All @@ -87,7 +87,7 @@ type subConfig struct {
}

// InitModule initializes the configuration.
func (cfg *Config) InitModule(mods *modules.Core) {
func (cfg *Config) InitModule(mods *modules.Core, _ modules.ScopeInfo) {
mods.Get(
&cfg.eventLoop,
&cfg.logger,
Expand Down Expand Up @@ -287,7 +287,7 @@ func (cfg *subConfig) Propose(proposal hotstuff.ProposeMsg) {
if cfg.cfg == nil {
return
}
ctx, cancel := synchronizer.TimeoutContext(cfg.eventLoop.Context(), cfg.eventLoop)
ctx, cancel := synchronizer.ScopedTimeoutContext(cfg.eventLoop.Context(), cfg.eventLoop, proposal.Pipe)
defer cancel()
cfg.cfg.Propose(
ctx,
Expand All @@ -302,7 +302,7 @@ func (cfg *subConfig) Timeout(msg hotstuff.TimeoutMsg) {
}

// will wait until the second timeout before canceling
ctx, cancel := synchronizer.TimeoutContext(cfg.eventLoop.Context(), cfg.eventLoop)
ctx, cancel := synchronizer.ScopedTimeoutContext(cfg.eventLoop.Context(), cfg.eventLoop, msg.Pipe)
defer cancel()

cfg.cfg.Timeout(
Expand Down
84 changes: 69 additions & 15 deletions backend/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,21 @@ import (
)

// Server is the Server-side of the gorums backend.
// It is responsible for calling handler methods on the consensus instance.
// It is responsible for calling handler methods on the pipe.
type Server struct {
blockChain modules.BlockChain
configuration modules.Configuration
eventLoop *eventloop.EventLoop
eventLoop *eventloop.ScopedEventLoop
logger logging.Logger
location string
locationInfo map[hotstuff.ID]string
latencyMatrix map[string]time.Duration
hackyLatency time.Duration
gorumsSrv *gorums.Server
}

// InitModule initializes the Server.
func (srv *Server) InitModule(mods *modules.Core) {
func (srv *Server) InitModule(mods *modules.Core, _ modules.ScopeInfo) {
mods.Get(
&srv.eventLoop,
&srv.configuration,
Expand Down Expand Up @@ -74,6 +75,26 @@ func (srv *Server) induceLatency(sender hotstuff.ID) {
<-timer1.C
}

func (srv *Server) SetHackyLatency(amount time.Duration) {
srv.hackyLatency = amount
}

// Alan: Hacky version of induceLatency which just blocks execution for an arbitrary time.
func (srv *Server) induceLatencyHacky(sender hotstuff.ID, callback func()) {
if srv.hackyLatency == 0 {
callback()
return
}
go func() {
senderLatency := srv.hackyLatency
senderLocation := srv.locationInfo[sender]
srv.logger.Debugf("latency from server %s to server %s is %s\n", srv.location, senderLocation, senderLatency)
timer1 := time.NewTimer(senderLatency)
<-timer1.C
callback()
}()
}

// GetGorumsServer returns the underlying gorums Server.
func (srv *Server) GetGorumsServer() *gorums.Server {
return srv.gorumsSrv
Expand Down Expand Up @@ -162,8 +183,14 @@ func (impl *serviceImpl) Propose(ctx gorums.ServerCtx, proposal *hotstuffpb.Prop
proposal.Block.Proposer = uint32(id)
proposeMsg := hotstuffpb.ProposalFromProto(proposal)
proposeMsg.ID = id
impl.srv.induceLatency(id)
impl.srv.eventLoop.AddEvent(proposeMsg)
impl.srv.induceLatencyHacky(id, func() {
if proposeMsg.Pipe.IsNull() {
impl.srv.eventLoop.AddScopedEvent(proposeMsg.Pipe, proposeMsg)
return
}

impl.srv.eventLoop.AddEvent(proposeMsg)
})
}

// Vote handles an incoming vote message.
Expand All @@ -173,10 +200,20 @@ func (impl *serviceImpl) Vote(ctx gorums.ServerCtx, cert *hotstuffpb.PartialCert
impl.srv.logger.Infof("Failed to get client ID: %v", err)
return
}
impl.srv.induceLatency(id)
impl.srv.eventLoop.AddEvent(hotstuff.VoteMsg{
ID: id,
PartialCert: hotstuffpb.PartialCertFromProto(cert),
impl.srv.induceLatencyHacky(id, func() {
pipe := hotstuff.Pipe(cert.Pipe)
if pipe.IsNull() {
impl.srv.eventLoop.AddScopedEvent(pipe, hotstuff.VoteMsg{
ID: id,
PartialCert: hotstuffpb.PartialCertFromProto(cert),
})
return
}

impl.srv.eventLoop.AddEvent(hotstuff.VoteMsg{
ID: id,
PartialCert: hotstuffpb.PartialCertFromProto(cert),
})
})
}

Expand All @@ -187,10 +224,20 @@ func (impl *serviceImpl) NewView(ctx gorums.ServerCtx, msg *hotstuffpb.SyncInfo)
impl.srv.logger.Infof("Failed to get client ID: %v", err)
return
}
impl.srv.induceLatency(id)
impl.srv.eventLoop.AddEvent(hotstuff.NewViewMsg{
ID: id,
SyncInfo: hotstuffpb.SyncInfoFromProto(msg),
impl.srv.induceLatencyHacky(id, func() {
pipe := hotstuff.Pipe(msg.Pipe)
if pipe.IsNull() {
impl.srv.eventLoop.AddScopedEvent(pipe, hotstuff.NewViewMsg{
ID: id,
SyncInfo: hotstuffpb.SyncInfoFromProto(msg),
})
return
}

impl.srv.eventLoop.AddEvent(hotstuff.NewViewMsg{
ID: id,
SyncInfo: hotstuffpb.SyncInfoFromProto(msg),
})
})
}

Expand All @@ -217,8 +264,15 @@ func (impl *serviceImpl) Timeout(ctx gorums.ServerCtx, msg *hotstuffpb.TimeoutMs
if err != nil {
impl.srv.logger.Infof("Could not get ID of replica: %v", err)
}
impl.srv.induceLatency(timeoutMsg.ID)
impl.srv.eventLoop.AddEvent(timeoutMsg)

impl.srv.induceLatencyHacky(timeoutMsg.ID, func() {
if timeoutMsg.Pipe.IsNull() {
impl.srv.eventLoop.AddScopedEvent(timeoutMsg.Pipe, timeoutMsg)
return
}

impl.srv.eventLoop.AddEvent(timeoutMsg)
})
}

type replicaConnected struct {
Expand Down
Loading