Skip to content

Commit

Permalink
draft: refactor chainsync client to fix race conditions and other issues
Browse files Browse the repository at this point in the history
  • Loading branch information
rakshasa committed May 13, 2024
1 parent c174202 commit 709acae
Show file tree
Hide file tree
Showing 3 changed files with 687 additions and 183 deletions.
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

0 comments on commit 709acae

Please sign in to comment.