From 0ed1bcd7c19de6bc4d93f977f05191a8cbcbaf2e Mon Sep 17 00:00:00 2001 From: Tudor Malene Date: Thu, 1 Aug 2024 12:17:48 +0100 Subject: [PATCH 1/7] add code to debug resource leak --- go/enclave/main/main.go | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/go/enclave/main/main.go b/go/enclave/main/main.go index 48ffc8c4be..6d4ae38e68 100644 --- a/go/enclave/main/main.go +++ b/go/enclave/main/main.go @@ -2,11 +2,13 @@ package main import ( "fmt" - "github.com/ten-protocol/go-ten/go/common/container" tenflag "github.com/ten-protocol/go-ten/go/common/flag" "github.com/ten-protocol/go-ten/go/config" enclavecontainer "github.com/ten-protocol/go-ten/go/enclave/container" + "os" + "runtime/pprof" + "time" ) // Runs an Obscuro enclave as a standalone process. @@ -25,6 +27,29 @@ func main() { panic(fmt.Errorf("unable to create config from flags - %w", err)) } + // temporary code to help identify OOM + go func() { + for { + heap, err := os.Open(fmt.Sprintf("heap_%s.pprof", time.Now().Format(time.RFC3339))) + if err != nil { + panic(fmt.Errorf("could not open CPU profile: %w", err)) + } + err = pprof.WriteHeapProfile(heap) + if err != nil { + panic(fmt.Errorf("could not write CPU profile: %w", err)) + } + stack, err := os.Open(fmt.Sprintf("heap_%s.pprof", time.Now().Format(time.RFC3339))) + if err != nil { + panic(fmt.Errorf("could not open CPU profile: %w", err)) + } + err = pprof.Lookup("goroutine").WriteTo(stack, 1) + if err != nil { + panic(fmt.Errorf("could not write CPU profile: %w", err)) + } + time.Sleep(1 * time.Hour) + } + }() + enclaveContainer := enclavecontainer.NewEnclaveContainerFromConfig(enclaveConfig) container.Serve(enclaveContainer) } From f5aeeb5414a59c038d70d88c1bd9614cb1513741 Mon Sep 17 00:00:00 2001 From: Tudor Malene Date: Thu, 1 Aug 2024 12:19:19 +0100 Subject: [PATCH 2/7] fix --- go/enclave/main/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go/enclave/main/main.go b/go/enclave/main/main.go index 6d4ae38e68..968c6bb6ed 100644 --- a/go/enclave/main/main.go +++ b/go/enclave/main/main.go @@ -38,7 +38,7 @@ func main() { if err != nil { panic(fmt.Errorf("could not write CPU profile: %w", err)) } - stack, err := os.Open(fmt.Sprintf("heap_%s.pprof", time.Now().Format(time.RFC3339))) + stack, err := os.Open(fmt.Sprintf("stack_%s.pprof", time.Now().Format(time.RFC3339))) if err != nil { panic(fmt.Errorf("could not open CPU profile: %w", err)) } From c375814ecead48cd0cfc60bf18e10aa8ee2a044c Mon Sep 17 00:00:00 2001 From: Tudor Malene Date: Thu, 1 Aug 2024 14:30:54 +0100 Subject: [PATCH 3/7] fix --- go/enclave/main/main.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/go/enclave/main/main.go b/go/enclave/main/main.go index 968c6bb6ed..a83dfda48e 100644 --- a/go/enclave/main/main.go +++ b/go/enclave/main/main.go @@ -30,7 +30,7 @@ func main() { // temporary code to help identify OOM go func() { for { - heap, err := os.Open(fmt.Sprintf("heap_%s.pprof", time.Now().Format(time.RFC3339))) + heap, err := os.Create(fmt.Sprintf("heap_%s.pprof", time.Now().Format(time.RFC3339))) if err != nil { panic(fmt.Errorf("could not open CPU profile: %w", err)) } @@ -38,7 +38,7 @@ func main() { if err != nil { panic(fmt.Errorf("could not write CPU profile: %w", err)) } - stack, err := os.Open(fmt.Sprintf("stack_%s.pprof", time.Now().Format(time.RFC3339))) + stack, err := os.Create(fmt.Sprintf("stack_%s.pprof", time.Now().Format(time.RFC3339))) if err != nil { panic(fmt.Errorf("could not open CPU profile: %w", err)) } From e9b2b21012f742d83dfef79f815496ac12ba1336 Mon Sep 17 00:00:00 2001 From: Tudor Malene Date: Thu, 1 Aug 2024 14:52:09 +0100 Subject: [PATCH 4/7] fix --- go/enclave/main/main.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/go/enclave/main/main.go b/go/enclave/main/main.go index a83dfda48e..1235eb8afa 100644 --- a/go/enclave/main/main.go +++ b/go/enclave/main/main.go @@ -30,17 +30,17 @@ func main() { // temporary code to help identify OOM go func() { for { - heap, err := os.Create(fmt.Sprintf("heap_%s.pprof", time.Now().Format(time.RFC3339))) + heap, err := os.Create(fmt.Sprintf("/heap_%d.pprof", time.Now().UnixMilli())) if err != nil { - panic(fmt.Errorf("could not open CPU profile: %w", err)) + panic(fmt.Errorf("could not open heap profile: %w", err)) } err = pprof.WriteHeapProfile(heap) if err != nil { panic(fmt.Errorf("could not write CPU profile: %w", err)) } - stack, err := os.Create(fmt.Sprintf("stack_%s.pprof", time.Now().Format(time.RFC3339))) + stack, err := os.Create(fmt.Sprintf("/stack_%d.pprof", time.Now().UnixMilli())) if err != nil { - panic(fmt.Errorf("could not open CPU profile: %w", err)) + panic(fmt.Errorf("could not open stack profile: %w", err)) } err = pprof.Lookup("goroutine").WriteTo(stack, 1) if err != nil { From 9b1a7732501bd4e8aef6721fa5f519dfa67ffb10 Mon Sep 17 00:00:00 2001 From: Tudor Malene Date: Thu, 1 Aug 2024 15:32:31 +0100 Subject: [PATCH 5/7] fix --- go/enclave/main/main.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/go/enclave/main/main.go b/go/enclave/main/main.go index 1235eb8afa..fa798e2241 100644 --- a/go/enclave/main/main.go +++ b/go/enclave/main/main.go @@ -30,7 +30,7 @@ func main() { // temporary code to help identify OOM go func() { for { - heap, err := os.Create(fmt.Sprintf("/heap_%d.pprof", time.Now().UnixMilli())) + heap, err := os.Create(fmt.Sprintf("/data/heap_%d.pprof", time.Now().UnixMilli())) if err != nil { panic(fmt.Errorf("could not open heap profile: %w", err)) } @@ -38,7 +38,7 @@ func main() { if err != nil { panic(fmt.Errorf("could not write CPU profile: %w", err)) } - stack, err := os.Create(fmt.Sprintf("/stack_%d.pprof", time.Now().UnixMilli())) + stack, err := os.Create(fmt.Sprintf("/data/stack_%d.pprof", time.Now().UnixMilli())) if err != nil { panic(fmt.Errorf("could not open stack profile: %w", err)) } From 74faf3505b475519baaed1a0a17734d7c0bd699c Mon Sep 17 00:00:00 2001 From: Tudor Malene Date: Tue, 20 Aug 2024 16:59:05 +0100 Subject: [PATCH 6/7] change brotli writer --- go/common/compression/data_compression_service.go | 3 ++- go/enclave/main/main.go | 7 ++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/go/common/compression/data_compression_service.go b/go/common/compression/data_compression_service.go index ed0048674d..445c87b94f 100644 --- a/go/common/compression/data_compression_service.go +++ b/go/common/compression/data_compression_service.go @@ -36,7 +36,8 @@ func (cs *brotliDataCompressionService) Decompress(in []byte) ([]byte, error) { func (cs *brotliDataCompressionService) compress(in []byte, level int) ([]byte, error) { var buf bytes.Buffer - writer := brotli.NewWriterLevel(&buf, level) + // writer := brotli.NewWriterLevel(&buf, level) + writer := brotli.NewWriterV2(&buf, level) _, err := writer.Write(in) if closeErr := writer.Close(); err == nil { err = closeErr diff --git a/go/enclave/main/main.go b/go/enclave/main/main.go index fa798e2241..d558de853b 100644 --- a/go/enclave/main/main.go +++ b/go/enclave/main/main.go @@ -2,13 +2,14 @@ package main import ( "fmt" + "os" + "runtime/pprof" + "time" + "github.com/ten-protocol/go-ten/go/common/container" tenflag "github.com/ten-protocol/go-ten/go/common/flag" "github.com/ten-protocol/go-ten/go/config" enclavecontainer "github.com/ten-protocol/go-ten/go/enclave/container" - "os" - "runtime/pprof" - "time" ) // Runs an Obscuro enclave as a standalone process. From 75b9b854ff6cacba9cf562f12e1782733344bdc6 Mon Sep 17 00:00:00 2001 From: Tudor Malene Date: Wed, 21 Aug 2024 11:01:51 +0100 Subject: [PATCH 7/7] fix --- go/host/enclave/guardian.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/go/host/enclave/guardian.go b/go/host/enclave/guardian.go index a6ccb8bbed..5738078d19 100644 --- a/go/host/enclave/guardian.go +++ b/go/host/enclave/guardian.go @@ -429,7 +429,8 @@ func (g *Guardian) submitL1Block(block *common.L1Block, isLatest bool) (bool, er // nullify all non-relevant transactions txs := block.Transactions() for i, rec := range receipts { - if rec == nil { + // the FetchObscuroReceipts method returns dummy receipts on non-relevant positions. + if rec.BlockNumber == nil { txs[i] = nil } }