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

draft: refactor chainsync client to fix race conditions and other issues #609

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
34 changes: 34 additions & 0 deletions cmd/gouroboros/chainsync.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,37 @@ func testChainSync(f *globalFlags) {
os.Exit(1)
}

// REMOVE: Test GetCurrentTip during chain sync.
// for i := 0; i < 10; i++ {
// go func() {
// last := uint64(0)
// count := 0

// // REMOVE.
// time.Sleep(3 * time.Second)

// fmt.Printf("Starting GetCurrentTip test\n")

// for {
// count++

// tip, err := oConn.ChainSync().Client.GetCurrentTip()
// if err != nil {
// fmt.Printf("ERROR: GetCurrentTip: %v\n", err)
// return
// }

// if tip.BlockNumber != last {
// fmt.Printf("tip: block:%d count:%d\n", tip.BlockNumber, count)
// last = tip.BlockNumber
// count = 0
// }

// time.Sleep(10 * time.Millisecond)
// }
// }()
// }

var point common.Point
if chainSyncFlags.tip {
tip, err := oConn.ChainSync().Client.GetCurrentTip()
Expand All @@ -226,9 +257,12 @@ func testChainSync(f *globalFlags) {
point = common.NewPointOrigin()
}
if chainSyncFlags.blockRange {
fmt.Printf("client: requesting block range\n")

start, end, err := oConn.ChainSync().Client.GetAvailableBlockRange(
[]common.Point{point},
)
fmt.Printf("client: block range: %d -> %d\n", start, end)
if err != nil {
fmt.Printf("ERROR: failed to get available block range: %s\n", err)
os.Exit(1)
Expand Down
4 changes: 4 additions & 0 deletions connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,10 @@ func (c *Connection) ProtocolVersion() (uint16, protocol.VersionData) {

// shutdown performs cleanup operations when the connection is shutdown, either due to explicit Close() or an error
func (c *Connection) shutdown() {
// Immediately close the chainsync client
if c.chainSync != nil {
c.chainSync.Client.Close()
}
// Gracefully stop the muxer
if c.muxer != nil {
c.muxer.Stop()
Expand Down
Loading
Loading