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

V2 #14

Draft
wants to merge 115 commits into
base: fix/audit
Choose a base branch
from
Draft

V2 #14

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
115 commits
Select commit Hold shift + click to select a range
cff51d2
new proto pkg and Makefile
dbrajovic Aug 12, 2023
b0e846a
define consensus message types
dbrajovic Aug 12, 2023
11b9094
happy flow + test
dbrajovic Aug 24, 2023
83ed8de
happy flow: validator is proposer
dbrajovic Aug 24, 2023
4631eed
refactor tests
dbrajovic Aug 24, 2023
0b80e87
split validator and verifier interface
dbrajovic Aug 28, 2023
491e60e
add MsgProposal validation tests
dbrajovic Aug 29, 2023
946c034
add MsgPrepare validation tests
dbrajovic Aug 29, 2023
9260d82
add MsgCommit validation tests
dbrajovic Aug 29, 2023
762b994
refactor sequencer.go
dbrajovic Aug 29, 2023
8e07f16
propose for higher rounds
dbrajovic Aug 30, 2023
f1683d7
higher round proposal (propose + accept) + tests
dbrajovic Aug 31, 2023
4480e77
add TestIsValidPreparedCertificate
dbrajovic Sep 1, 2023
a5cae13
add TestIsValidRoundChangeCertificate
dbrajovic Sep 1, 2023
2d1807c
refactor
dbrajovic Sep 1, 2023
b5c9087
clean up types pkg
dbrajovic Sep 6, 2023
423c2c4
util tests
dbrajovic Sep 6, 2023
c23fa48
define basic types + test
dbrajovic Sep 6, 2023
68de893
impl unique From constraint + test
dbrajovic Sep 6, 2023
6fc58c1
impl generic msg collection
dbrajovic Sep 6, 2023
fc2f1d3
refactor tests
dbrajovic Sep 6, 2023
6ae7303
tests
dbrajovic Sep 6, 2023
9ecbb35
refactor
dbrajovic Sep 6, 2023
8cd3891
MsgProposal feed + test
dbrajovic Sep 6, 2023
e249215
fix bug + test
dbrajovic Sep 6, 2023
d0d8b95
refactor feed mechanism
dbrajovic Sep 7, 2023
c1c11a9
add todos
dbrajovic Sep 7, 2023
55178e8
redefine interface
dbrajovic Sep 7, 2023
4452307
tests
dbrajovic Sep 7, 2023
55e2db8
refactor
dbrajovic Sep 7, 2023
caa24e2
replace collection with thread safe
dbrajovic Sep 7, 2023
f98c4da
add tests for other msg types
dbrajovic Sep 7, 2023
40898c4
define ibft types
dbrajovic Sep 7, 2023
8d1a95d
refactor sequencer to use ibft interfaces
dbrajovic Sep 7, 2023
100c340
replace ibft.Context in sequencer
dbrajovic Sep 7, 2023
1f6204c
test
dbrajovic Sep 8, 2023
da71903
reorganize files
dbrajovic Sep 8, 2023
71ff3fa
refactor tests
dbrajovic Sep 8, 2023
b69de33
remove old impl
dbrajovic Sep 8, 2023
87633e6
linter
dbrajovic Sep 8, 2023
a6a0bf7
add msg caching
dbrajovic Sep 8, 2023
659c22b
refactor
dbrajovic Sep 8, 2023
fa3bde0
linter
dbrajovic Sep 8, 2023
2effe25
comments
dbrajovic Sep 8, 2023
8b0a03c
comments
dbrajovic Sep 8, 2023
cef7140
refactor
dbrajovic Sep 8, 2023
7f01c25
comments
dbrajovic Sep 8, 2023
0348cf5
code style
dbrajovic Sep 8, 2023
196a684
remove
dbrajovic Sep 8, 2023
b794de4
fix race
dbrajovic Sep 8, 2023
33a6ecd
linter
dbrajovic Sep 8, 2023
012f008
replace store methods with generic func
dbrajovic Sep 8, 2023
23a01b0
remove unused error
dbrajovic Sep 8, 2023
5977348
refactor message/store types
dbrajovic Feb 20, 2024
b527968
update Go files
dbrajovic Feb 20, 2024
1cdacdb
remove redunant func
dbrajovic Feb 20, 2024
210ba70
linter
dbrajovic Feb 20, 2024
468d8b6
clean sequencer_test
dbrajovic Feb 21, 2024
7623179
linter
dbrajovic Feb 21, 2024
cb6c890
refactor sequencer test
dbrajovic Feb 21, 2024
8550bd6
comments and symbol names
dbrajovic Feb 21, 2024
232564a
change type constraint to pointers
dbrajovic Feb 21, 2024
e5bc141
refactor store
dbrajovic Feb 22, 2024
0da9d22
add types test
dbrajovic Feb 22, 2024
2d8f423
clean tests
dbrajovic Feb 22, 2024
5ae9b45
linter
dbrajovic Feb 22, 2024
fe53811
add test folder
dbrajovic Feb 23, 2024
a566f61
fix keccak usage
dbrajovic Feb 23, 2024
8c0fa9c
Merge branch 'v2' into v2-test
dbrajovic Feb 23, 2024
723afed
add Test_All_Honest_Validators
dbrajovic Feb 23, 2024
96cbdf1
basic happy flow test
dbrajovic Feb 23, 2024
dbe889b
add more test cases
dbrajovic Feb 25, 2024
17b8939
simplify test pkg
dbrajovic Feb 26, 2024
c648e46
simplify message wrapping
dbrajovic Feb 26, 2024
3e32052
simplify Quorum interface
dbrajovic Feb 26, 2024
49bb0ef
remove SigRecover and update Verfier
dbrajovic Feb 26, 2024
6d44d67
linter
dbrajovic Feb 26, 2024
78096da
simplify await methods
dbrajovic Feb 26, 2024
f4c9bf2
linter
dbrajovic Feb 26, 2024
c1fb43a
add another flow case
dbrajovic Feb 26, 2024
02404c5
add consensus pkg
dbrajovic Feb 29, 2024
958bb34
refactor
dbrajovic Mar 4, 2024
4b02862
refactor MessageFeed interface
dbrajovic Mar 7, 2024
2cf23fb
refactor mocks
dbrajovic Mar 7, 2024
9d948f3
bump Go version
dbrajovic Mar 8, 2024
23c09cc
built-in max doesn't work as expected
dbrajovic Mar 8, 2024
bc80527
remove import
dbrajovic Mar 8, 2024
d82ca42
refactor
dbrajovic Mar 8, 2024
7f2c5e9
add test Test_EngineConfig
dbrajovic Mar 8, 2024
bb74f98
add Test_Engine_Add_Message
dbrajovic Mar 8, 2024
8ef5412
add Test_Engine_Finalize_Sequence
dbrajovic Mar 8, 2024
69928d4
remove messages after FinalizeSequence
dbrajovic Mar 11, 2024
938c4ef
cleanup
dbrajovic Mar 11, 2024
0b4614c
linter
dbrajovic Mar 11, 2024
e42bbae
remove redundant methods
dbrajovic Mar 11, 2024
ff830e8
add err values
dbrajovic Mar 11, 2024
f6c51e4
go mod tidy
dbrajovic Mar 11, 2024
e79ecb7
update README
dbrajovic Mar 11, 2024
8526d91
remove file
dbrajovic Mar 11, 2024
eee9347
refactor
dbrajovic Jun 22, 2024
af053b5
rename
dbrajovic Jun 23, 2024
77fe18c
update proto
dbrajovic Jun 23, 2024
d3ba87e
rename
dbrajovic Jun 24, 2024
56657ee
update go.mod
dbrajovic Jun 24, 2024
e46050c
chore: update go.mod
dbrajovic Jul 22, 2024
2a3f98a
adapt to new interfaces
dbrajovic Jul 29, 2024
466c8f3
refactor message pkg
dbrajovic Aug 6, 2024
29514a0
fix msg_test.go
dbrajovic Aug 7, 2024
87208d2
remove view type
dbrajovic Aug 7, 2024
29d417c
fix sequencer_test.go
dbrajovic Aug 8, 2024
4fcd2e8
cleanup
dbrajovic Aug 11, 2024
b82ad1d
store pkg tests
dbrajovic Aug 12, 2024
0f0b9ad
go mod tidy
dbrajovic Aug 12, 2024
68c3265
comments
dbrajovic Aug 12, 2024
f8732b8
linter
dbrajovic Aug 12, 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
3 changes: 0 additions & 3 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ linters:
- gosimple # Code simplification
- govet # Official Go tool
- ineffassign # Detects when assignments to existing variables are not used
- interfacer # Top-level interface suggestions
- nakedret # Finds naked/bare returns and requires change them
- nilerr # Requires explicit returns
- nilnil # Requires explicit returns
Expand All @@ -60,15 +59,13 @@ linters:
- gocheckcompilerdirectives # Checks that compiler directive comments (//go:) are valid
- gochecknoinits # Checks for init methods
- whitespace # Tool for detection of leading and trailing whitespace
- wsl # Forces you to use empty lines
- unconvert # Unnecessary type conversions
- tparallel # Detects inappropriate usage of t.Parallel() method in your Go test codes
- thelper # Detects golang test helpers without t.Helper() call and checks the consistency of test helpers
- stylecheck # Stylecheck is a replacement for golint
- prealloc # Finds slice declarations that could potentially be pre-allocated
- predeclared # Finds code that shadows one of Go's predeclared identifiers
- nolintlint # Ill-formed or insufficient nolint directives
- nlreturn # Checks for a new line before return and branch statements to increase code clarity
- misspell # Misspelled English words in comments
- makezero # Finds slice declarations with non-zero initial length
- lll # Long lines
Expand Down
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ fixalign:

.PHONY: protoc
protoc:
protoc --go_out=. messages/proto/messages.proto
protoc --go_out=./ ./proto/*.proto

90 changes: 44 additions & 46 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,72 +1,70 @@
## Overview

`go-ibft` is a simple, straightforward, IBFT state machine implementation.
`go-ibft` provides a light-weight engine implementation of the IBFT 2.0 block finalization algorithm.

It doesn't contain fancy synchronization logic, or any kind of transaction execution layer.
Instead, `go-ibft` is designed from the ground up to respect and adhere to the `IBFT 2.0` specification document.

Inside this package, you’ll find that it solves the underlying liveness and persistence issues of the original IBFT
specification, as well as that it contains a plethora of optimizations that make it faster and more lightweight. For a
complete specification overview on the package, you can check out the official documentation.

As mentioned before, `go-ibft` implements basic IBFT 2.0 state machine logic, meaning it doesn’t have any kind of
transaction execution or block building mechanics. That responsibility is left to the `Backend` implementation.
Due to its simple API and minimal client dependencies (see `ibft.go`) the engine is designed to work in parallel with a block syncing mechanism (as described in the original document).
For the full protocol specification, see the official doc.

## Installation

To get up and running with the `go-ibft` package, you can pull it into your project using:
Required Go version `1.22`

`go get github.com/madz-lab/go-ibft`
From your project root directory run:

Currently, the minimum required go version is `go 1.19`.
`$ go get github.com/madz-lab/go-ibft`

## Usage Examples

```go
package main

import "github.com/madz-lab/go-ibft"
import (
"context"
"time"

// IBFTBackend is the structure that implements all required
// go-ibft Backend interfaces
type IBFTBackend struct {
// ...
}
"github.com/madz-lab/go-ibft"
"github.com/madz-lab/go-ibft/engine"
"github.com/madz-lab/go-ibft/message/types"
)

// IBFTLogger is the structure that implements all required
// go-ibft Logger interface
type IBFTLogger struct {
// ...
}
func main() {

// IBFTTransport is the structure that implements all required
// go-ibft Transport interface
type IBFTTransport struct {
var (
// Provide external dependencies
validator ibft.Validator
keccak ibft.Keccak
quorum ibft.Quorum
round0Duration time.Duration

proposalTransport ibft.Transport[*types.MsgProposal]
prepareTransport ibft.Transport[*types.MsgPrepare]
commitTransport ibft.Transport[*types.MsgCommit]
roundChangeTransport ibft.Transport[*types.MsgRoundChange]
)

// ...
}

// ...

func main() {
backend := NewIBFTBackned(...)
logger := NewIBFTLogger(...)
transport := NewIBFTTransport(...)

ibft := NewIBFT(logger, backend, transport)
cfg := engine.Config{
TransportMsgProposal: proposalTransport,
TransportMsgPrepare: prepareTransport,
TransportMsgCommit: commitTransport,
TransportMsgRoundChange: roundChangeTransport,
Quorum: quorum,
Keccak: keccak,
Round0Duration: round0Duration,
}

blockHeight := uint64(1)
ctx, cancelFn := context.WithCancel(context.Background())
e := engine.NewEngine(validator, cfg)

go func() {
// Run the consensus sequence for the block height.
// When the method returns, that means that
// consensus was reached
i := RunSequence(ctx, blockHeight)
}
var msg types.Message

// ...
// Receive consensus messages gossiped in the network
_ = e.AddMessage(msg)
}()

// Stop the sequence by cancelling the context
cancelFn()
// await proposal to be finalized for current sequence
_ = e.FinalizeSequence(context.Background(), 101)
}

```
71 changes: 0 additions & 71 deletions core/backend.go

This file was deleted.

Loading