From 50a52b218a0c9eeb80f318402b0d20cdbde879a3 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Sun, 3 Mar 2024 02:25:33 +0000 Subject: [PATCH 01/13] optimize encoder interpolation latency --- encoding/rs/encode.go | 104 +++++++++++++++++++++++++++++------ encoding/rs/encoder.go | 5 ++ encoding/rs/interpolation.go | 41 +++++++++++--- 3 files changed, 126 insertions(+), 24 deletions(-) diff --git a/encoding/rs/encode.go b/encoding/rs/encode.go index 696ba07b93..0ff72aea6e 100644 --- a/encoding/rs/encode.go +++ b/encoding/rs/encode.go @@ -77,31 +77,68 @@ func (g *Encoder) MakeFrames( indices := make([]uint32, 0) frames := make([]Frame, g.NumChunks) - for i := uint64(0); i < uint64(g.NumChunks); i++ { + jobChan := make(chan JobRequest, g.NumRSWorker) + results := make(chan error, g.NumRSWorker) + + for w := uint64(0); w < uint64(g.NumRSWorker); w++ { + go g.interpolyWorker( + polyEvals, + jobChan, + results, + frames, + ) + } - // finds out which coset leader i-th node is having + for i := uint64(0); i < g.NumChunks; i++ { j := rb.ReverseBitsLimited(uint32(g.NumChunks), uint32(i)) - - // mutltiprover return proof in butterfly order - frame := Frame{} + jr := JobRequest{ + Index: uint64(i), + FrameIndex: k, + } + jobChan <- jr + k++ indices = append(indices, j) + } + close(jobChan) - ys := polyEvals[g.ChunkLength*i : g.ChunkLength*(i+1)] - err := rb.ReverseBitOrderFr(ys) - if err != nil { - return nil, nil, err - } - coeffs, err := g.GetInterpolationPolyCoeff(ys, uint32(j)) - if err != nil { - return nil, nil, err + for w := uint64(0); w < uint64(g.NumRSWorker); w++ { + interPolyErr := <-results + if interPolyErr != nil { + err = interPolyErr } + } - frame.Coeffs = coeffs - - frames[k] = frame - k++ + if err != nil { + return nil, nil, fmt.Errorf("proof worker error: %v", err) } + /* + for i := uint64(0); i < uint64(g.NumChunks); i++ { + + // finds out which coset leader i-th node is having + j := rb.ReverseBitsLimited(uint32(g.NumChunks), uint32(i)) + + // mutltiprover return proof in butterfly order + frame := Frame{} + indices = append(indices, j) + + ys := polyEvals[g.ChunkLength*i : g.ChunkLength*(i+1)] + err := rb.ReverseBitOrderFr(ys) + if err != nil { + return nil, nil, err + } + coeffs, err := g.GetInterpolationPolyCoeff(ys, uint32(j)) + if err != nil { + return nil, nil, err + } + + frame.Coeffs = coeffs + + frames[k] = frame + k++ + } + */ + return frames, indices, nil } @@ -127,3 +164,36 @@ func (g *Encoder) ExtendPolyEval(coeffs []fr.Element) ([]fr.Element, []fr.Elemen return evals, pdCoeffs, nil } + +type JobRequest struct { + Index uint64 + FrameIndex uint64 +} + +func (g *Encoder) interpolyWorker( + polyEvals []fr.Element, + jobChan <-chan JobRequest, + results chan<- error, + frames []Frame, +) { + + for jr := range jobChan { + i := jr.Index + k := jr.FrameIndex + j := rb.ReverseBitsLimited(uint32(g.NumChunks), uint32(i)) + ys := polyEvals[g.ChunkLength*i : g.ChunkLength*(i+1)] + err := rb.ReverseBitOrderFr(ys) + if err != nil { + results <- err + } + coeffs, err := g.GetInterpolationPolyCoeff(ys, uint32(j)) + if err != nil { + results <- err + } + + frames[k].Coeffs = coeffs + } + + results <- nil + +} diff --git a/encoding/rs/encoder.go b/encoding/rs/encoder.go index 3d6a4346e9..7eeb1d7b6c 100644 --- a/encoding/rs/encoder.go +++ b/encoding/rs/encoder.go @@ -2,9 +2,11 @@ package rs import ( "math" + "runtime" "github.com/Layr-Labs/eigenda/encoding" "github.com/Layr-Labs/eigenda/encoding/fft" + //"github.com/consensys/gnark-crypto/ecc/bn254/fr" ) type Encoder struct { @@ -13,6 +15,8 @@ type Encoder struct { Fs *fft.FFTSettings verbose bool + + NumRSWorker int } // The function creates a high level struct that determines the encoding the a data of a @@ -37,6 +41,7 @@ func NewEncoder(params encoding.EncodingParams, verbose bool) (*Encoder, error) EncodingParams: params, Fs: fs, verbose: verbose, + NumRSWorker: runtime.GOMAXPROCS(0), }, nil } diff --git a/encoding/rs/interpolation.go b/encoding/rs/interpolation.go index 5aa062edb7..e71b41fe5e 100644 --- a/encoding/rs/interpolation.go +++ b/encoding/rs/interpolation.go @@ -54,9 +54,9 @@ func (g *Encoder) GetInterpolationPolyEval( //var tmp, tmp2 fr.Element for i := 0; i < len(interpolationPoly); i++ { shiftedInterpolationPoly[i].Mul(&interpolationPoly[i], &wPow) - + wPow.Mul(&wPow, &w) - + } err := g.Fs.InplaceFFT(shiftedInterpolationPoly, evals, false) @@ -74,18 +74,45 @@ func (g *Encoder) GetInterpolationPolyCoeff(chunk []fr.Element, k uint32) ([]fr. } var wPow fr.Element wPow.SetOne() - + var tmp, tmp2 fr.Element for i := 0; i < len(chunk); i++ { tmp.Inverse(&wPow) - + tmp2.Mul(&shiftedInterpolationPoly[i], &tmp) - + coeffs[i].Set(&tmp2) - + tmp.Mul(&wPow, &w) - + wPow.Set(&tmp) } return coeffs, nil } + +/* +// exp is the exponent for the entire fft inverse root of unity array +func (g *Encoder) GetInvRootOfUnityArray(exp uint8) []fr.Element { + rous, ok := g.InvRootOfUnityTable[exp] + if !ok { + rous = g.CreateRootsOfUnityArray(exp) + g.InvRootOfUnityTable[exp] = rous + } + return rous +} + +func (g *Encoder) CreateRootsOfUnityArray(exp uint8) []fr.Element { + w := g.Fs.ExpandedRootsOfUnity[uint64(k)] + for i := 0; i < len(chunk); i++ { + tmp.Inverse(&wPow) + + tmp2.Mul(&shiftedInterpolationPoly[i], &tmp) + + coeffs[i].Set(&tmp2) + + tmp.Mul(&wPow, &w) + + wPow.Set(&tmp) + } +} +*/ From 88ffc29a6b2142b5114307399023063ad41495ae Mon Sep 17 00:00:00 2001 From: Daniel Mancia <21249320+dmanc@users.noreply.github.com> Date: Sat, 2 Mar 2024 16:26:18 -0800 Subject: [PATCH 02/13] fix: --- disperser/cmd/encoder/main.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/disperser/cmd/encoder/main.go b/disperser/cmd/encoder/main.go index 6c674f613d..d05174703f 100644 --- a/disperser/cmd/encoder/main.go +++ b/disperser/cmd/encoder/main.go @@ -4,9 +4,11 @@ import ( "context" "fmt" "log" + "net/http" "os" "github.com/Layr-Labs/eigenda/common" + "github.com/Layr-Labs/eigenda/disperser/cmd/encoder/flags" "github.com/urfave/cli" ) @@ -54,6 +56,11 @@ func RunEncoderServer(ctx *cli.Context) error { } defer enc.Close() + // Start pprof + go func() { + http.ListenAndServe(":6060", nil) + }() + err = enc.Start(context.Background()) if err != nil { return err From 97b5e397aed1dbef86aaa4daca53102f1c083a97 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Sun, 3 Mar 2024 21:32:16 +0000 Subject: [PATCH 03/13] remove computing inverse by lookingup rootofunity backward --- encoding/rs/encode.go | 14 ++++++++--- encoding/rs/interpolation.go | 49 ++++++++---------------------------- 2 files changed, 20 insertions(+), 43 deletions(-) diff --git a/encoding/rs/encode.go b/encoding/rs/encode.go index 0ff72aea6e..4961e04cbd 100644 --- a/encoding/rs/encode.go +++ b/encoding/rs/encode.go @@ -77,10 +77,16 @@ func (g *Encoder) MakeFrames( indices := make([]uint32, 0) frames := make([]Frame, g.NumChunks) - jobChan := make(chan JobRequest, g.NumRSWorker) - results := make(chan error, g.NumRSWorker) + numWorker := uint64(g.NumRSWorker) - for w := uint64(0); w < uint64(g.NumRSWorker); w++ { + if uint64(numWorker) > g.NumChunks { + numWorker = g.NumChunks + } + + jobChan := make(chan JobRequest, numWorker) + results := make(chan error, numWorker) + + for w := uint64(0); w < uint64(numWorker); w++ { go g.interpolyWorker( polyEvals, jobChan, @@ -101,7 +107,7 @@ func (g *Encoder) MakeFrames( } close(jobChan) - for w := uint64(0); w < uint64(g.NumRSWorker); w++ { + for w := uint64(0); w < uint64(numWorker); w++ { interPolyErr := <-results if interPolyErr != nil { err = interPolyErr diff --git a/encoding/rs/interpolation.go b/encoding/rs/interpolation.go index e71b41fe5e..b6db88d8e7 100644 --- a/encoding/rs/interpolation.go +++ b/encoding/rs/interpolation.go @@ -54,9 +54,7 @@ func (g *Encoder) GetInterpolationPolyEval( //var tmp, tmp2 fr.Element for i := 0; i < len(interpolationPoly); i++ { shiftedInterpolationPoly[i].Mul(&interpolationPoly[i], &wPow) - wPow.Mul(&wPow, &w) - } err := g.Fs.InplaceFFT(shiftedInterpolationPoly, evals, false) @@ -66,53 +64,26 @@ func (g *Encoder) GetInterpolationPolyEval( // Since both F W are invertible, c = W^-1 F^-1 d, convert it back. F W W^-1 F^-1 d = c func (g *Encoder) GetInterpolationPolyCoeff(chunk []fr.Element, k uint32) ([]fr.Element, error) { coeffs := make([]fr.Element, g.ChunkLength) - w := g.Fs.ExpandedRootsOfUnity[uint64(k)] + //w := g.Fs.ExpandedRootsOfUnity[uint64(k)] shiftedInterpolationPoly := make([]fr.Element, len(chunk)) err := g.Fs.InplaceFFT(chunk, shiftedInterpolationPoly, true) if err != nil { return coeffs, err } - var wPow fr.Element - wPow.SetOne() - var tmp, tmp2 fr.Element - for i := 0; i < len(chunk); i++ { - tmp.Inverse(&wPow) + wInvPowLookup := make([]fr.Element, len(chunk)) - tmp2.Mul(&shiftedInterpolationPoly[i], &tmp) - - coeffs[i].Set(&tmp2) - - tmp.Mul(&wPow, &w) - - wPow.Set(&tmp) - } - return coeffs, nil -} + mod := int32(len(g.Fs.ExpandedRootsOfUnity) - 1) -/* -// exp is the exponent for the entire fft inverse root of unity array -func (g *Encoder) GetInvRootOfUnityArray(exp uint8) []fr.Element { - rous, ok := g.InvRootOfUnityTable[exp] - if !ok { - rous = g.CreateRootsOfUnityArray(exp) - g.InvRootOfUnityTable[exp] = rous + // We cam lookup the inverse power by counting RootOfUnity backward + for i := int32(0); i < int32(len(chunk)); i++ { + j := (-int32(k)*i)%mod + mod + wInvPowLookup[i] = g.Fs.ExpandedRootsOfUnity[j] } - return rous -} -func (g *Encoder) CreateRootsOfUnityArray(exp uint8) []fr.Element { - w := g.Fs.ExpandedRootsOfUnity[uint64(k)] for i := 0; i < len(chunk); i++ { - tmp.Inverse(&wPow) - - tmp2.Mul(&shiftedInterpolationPoly[i], &tmp) - - coeffs[i].Set(&tmp2) - - tmp.Mul(&wPow, &w) - - wPow.Set(&tmp) + coeffs[i].Mul(&shiftedInterpolationPoly[i], &wInvPowLookup[i]) } + + return coeffs, nil } -*/ From d8b637b00febdf37d29d5d6818d2cb49fb2ad31d Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Sun, 3 Mar 2024 21:53:42 +0000 Subject: [PATCH 04/13] rm encoder pprof --- disperser/cmd/encoder/main.go | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/disperser/cmd/encoder/main.go b/disperser/cmd/encoder/main.go index d05174703f..f6c7504819 100644 --- a/disperser/cmd/encoder/main.go +++ b/disperser/cmd/encoder/main.go @@ -4,11 +4,11 @@ import ( "context" "fmt" "log" - "net/http" "os" "github.com/Layr-Labs/eigenda/common" + "github.com/Layr-Labs/eigenda/disperser/cmd/encoder/flags" "github.com/urfave/cli" ) @@ -56,11 +56,6 @@ func RunEncoderServer(ctx *cli.Context) error { } defer enc.Close() - // Start pprof - go func() { - http.ListenAndServe(":6060", nil) - }() - err = enc.Start(context.Background()) if err != nil { return err From 09e4e19c78d99b9bbfcaed6d7c6aa9a19a74a765 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Sun, 3 Mar 2024 22:28:44 +0000 Subject: [PATCH 05/13] rm comments --- encoding/rs/encode.go | 27 --------------------------- encoding/rs/encoder.go | 1 - 2 files changed, 28 deletions(-) diff --git a/encoding/rs/encode.go b/encoding/rs/encode.go index 4961e04cbd..d78ccc4452 100644 --- a/encoding/rs/encode.go +++ b/encoding/rs/encode.go @@ -118,33 +118,6 @@ func (g *Encoder) MakeFrames( return nil, nil, fmt.Errorf("proof worker error: %v", err) } - /* - for i := uint64(0); i < uint64(g.NumChunks); i++ { - - // finds out which coset leader i-th node is having - j := rb.ReverseBitsLimited(uint32(g.NumChunks), uint32(i)) - - // mutltiprover return proof in butterfly order - frame := Frame{} - indices = append(indices, j) - - ys := polyEvals[g.ChunkLength*i : g.ChunkLength*(i+1)] - err := rb.ReverseBitOrderFr(ys) - if err != nil { - return nil, nil, err - } - coeffs, err := g.GetInterpolationPolyCoeff(ys, uint32(j)) - if err != nil { - return nil, nil, err - } - - frame.Coeffs = coeffs - - frames[k] = frame - k++ - } - */ - return frames, indices, nil } diff --git a/encoding/rs/encoder.go b/encoding/rs/encoder.go index 7eeb1d7b6c..0b9fcdb15d 100644 --- a/encoding/rs/encoder.go +++ b/encoding/rs/encoder.go @@ -6,7 +6,6 @@ import ( "github.com/Layr-Labs/eigenda/encoding" "github.com/Layr-Labs/eigenda/encoding/fft" - //"github.com/consensys/gnark-crypto/ecc/bn254/fr" ) type Encoder struct { From c6ba77b1d60503edc40c9c7cfa937a55ea419017 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Sun, 3 Mar 2024 22:46:32 +0000 Subject: [PATCH 06/13] more efficient --- encoding/rs/interpolation.go | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/encoding/rs/interpolation.go b/encoding/rs/interpolation.go index b6db88d8e7..13650979ae 100644 --- a/encoding/rs/interpolation.go +++ b/encoding/rs/interpolation.go @@ -64,25 +64,18 @@ func (g *Encoder) GetInterpolationPolyEval( // Since both F W are invertible, c = W^-1 F^-1 d, convert it back. F W W^-1 F^-1 d = c func (g *Encoder) GetInterpolationPolyCoeff(chunk []fr.Element, k uint32) ([]fr.Element, error) { coeffs := make([]fr.Element, g.ChunkLength) - //w := g.Fs.ExpandedRootsOfUnity[uint64(k)] shiftedInterpolationPoly := make([]fr.Element, len(chunk)) err := g.Fs.InplaceFFT(chunk, shiftedInterpolationPoly, true) if err != nil { return coeffs, err } - wInvPowLookup := make([]fr.Element, len(chunk)) - mod := int32(len(g.Fs.ExpandedRootsOfUnity) - 1) - // We cam lookup the inverse power by counting RootOfUnity backward - for i := int32(0); i < int32(len(chunk)); i++ { - j := (-int32(k)*i)%mod + mod - wInvPowLookup[i] = g.Fs.ExpandedRootsOfUnity[j] - } - for i := 0; i < len(chunk); i++ { - coeffs[i].Mul(&shiftedInterpolationPoly[i], &wInvPowLookup[i]) + // We cam lookup the inverse power by counting RootOfUnity backward + j := (-int32(k)*int32(i))%mod + mod + coeffs[i].Mul(&shiftedInterpolationPoly[i], &g.Fs.ExpandedRootsOfUnity[j]) } return coeffs, nil From 575c1df1a18d03a3ad46c3f653f1fe28e8cd35ad Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Tue, 5 Mar 2024 02:41:12 +0000 Subject: [PATCH 07/13] return early if error happened inside worker thread --- encoding/kzg/prover/parametrized_prover.go | 1 + encoding/rs/encode.go | 2 ++ encoding/rs/interpolation.go | 2 +- 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/encoding/kzg/prover/parametrized_prover.go b/encoding/kzg/prover/parametrized_prover.go index b8eba9c9fa..0c9dc7c594 100644 --- a/encoding/kzg/prover/parametrized_prover.go +++ b/encoding/kzg/prover/parametrized_prover.go @@ -225,6 +225,7 @@ func (p *ParametrizedProver) proofWorker( points: nil, err: err, } + return } for i := 0; i < len(coeffs); i++ { diff --git a/encoding/rs/encode.go b/encoding/rs/encode.go index d78ccc4452..21755ec2a3 100644 --- a/encoding/rs/encode.go +++ b/encoding/rs/encode.go @@ -164,10 +164,12 @@ func (g *Encoder) interpolyWorker( err := rb.ReverseBitOrderFr(ys) if err != nil { results <- err + return } coeffs, err := g.GetInterpolationPolyCoeff(ys, uint32(j)) if err != nil { results <- err + return } frames[k].Coeffs = coeffs diff --git a/encoding/rs/interpolation.go b/encoding/rs/interpolation.go index 13650979ae..405799d0d2 100644 --- a/encoding/rs/interpolation.go +++ b/encoding/rs/interpolation.go @@ -73,7 +73,7 @@ func (g *Encoder) GetInterpolationPolyCoeff(chunk []fr.Element, k uint32) ([]fr. mod := int32(len(g.Fs.ExpandedRootsOfUnity) - 1) for i := 0; i < len(chunk); i++ { - // We cam lookup the inverse power by counting RootOfUnity backward + // We can lookup the inverse power by counting RootOfUnity backward j := (-int32(k)*int32(i))%mod + mod coeffs[i].Mul(&shiftedInterpolationPoly[i], &g.Fs.ExpandedRootsOfUnity[j]) } From 84dc3c018e0d9b3451ec56bfe1645c49ac1a960b Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Wed, 20 Mar 2024 18:02:13 +0000 Subject: [PATCH 08/13] fix return to continue --- encoding/rs/encode.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/encoding/rs/encode.go b/encoding/rs/encode.go index 21755ec2a3..e757d6579e 100644 --- a/encoding/rs/encode.go +++ b/encoding/rs/encode.go @@ -164,12 +164,12 @@ func (g *Encoder) interpolyWorker( err := rb.ReverseBitOrderFr(ys) if err != nil { results <- err - return + continue } coeffs, err := g.GetInterpolationPolyCoeff(ys, uint32(j)) if err != nil { results <- err - return + continue } frames[k].Coeffs = coeffs From 55c9882026fc763fcae6222c0c42c2b1d23ee7f6 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Wed, 20 Mar 2024 18:11:22 +0000 Subject: [PATCH 09/13] change return to continue --- encoding/rs/encode.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/encoding/rs/encode.go b/encoding/rs/encode.go index e757d6579e..44311f9cb0 100644 --- a/encoding/rs/encode.go +++ b/encoding/rs/encode.go @@ -56,8 +56,8 @@ func (g *Encoder) Encode(inputFr []fr.Element) (*GlobalPoly, []Frame, []uint32, return nil, nil, nil, err } - log.Printf(" SUMMARY: Encode %v byte among %v numNode takes %v\n", - len(inputFr)*encoding.BYTES_PER_COEFFICIENT, g.NumChunks, time.Since(start)) + log.Printf(" SUMMARY: RSEncode %v byte among %v numNode with chunkSize %v takes %v\n", + len(inputFr)*encoding.BYTES_PER_COEFFICIENT, g.NumChunks, g.ChunkLength, time.Since(start)) return poly, frames, indices, nil } From 2ee68ebb737eac5bc926cf336b1971d07acc9958 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Wed, 20 Mar 2024 18:15:21 +0000 Subject: [PATCH 10/13] rebase --- encoding/rs/encode.go | 1 + 1 file changed, 1 insertion(+) diff --git a/encoding/rs/encode.go b/encoding/rs/encode.go index 44311f9cb0..b6472afb5a 100644 --- a/encoding/rs/encode.go +++ b/encoding/rs/encode.go @@ -2,6 +2,7 @@ package rs import ( "errors" + "fmt" "log" "time" From 331b14de6000994ff5d7b72dc21d30a4d8ff873f Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Wed, 20 Mar 2024 18:24:30 +0000 Subject: [PATCH 11/13] fix return to continue --- disperser/cmd/encoder/main.go | 1 - encoding/kzg/prover/parametrized_prover.go | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/disperser/cmd/encoder/main.go b/disperser/cmd/encoder/main.go index f6c7504819..a9159e6c4c 100644 --- a/disperser/cmd/encoder/main.go +++ b/disperser/cmd/encoder/main.go @@ -8,7 +8,6 @@ import ( "github.com/Layr-Labs/eigenda/common" - "github.com/Layr-Labs/eigenda/disperser/cmd/encoder/flags" "github.com/urfave/cli" ) diff --git a/encoding/kzg/prover/parametrized_prover.go b/encoding/kzg/prover/parametrized_prover.go index 0c9dc7c594..e87e5e00f8 100644 --- a/encoding/kzg/prover/parametrized_prover.go +++ b/encoding/kzg/prover/parametrized_prover.go @@ -225,7 +225,7 @@ func (p *ParametrizedProver) proofWorker( points: nil, err: err, } - return + continue } for i := 0; i < len(coeffs); i++ { From c981800c06f0adf2352eb66514bcd8ce43aaeac4 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Fri, 22 Mar 2024 17:14:38 +0000 Subject: [PATCH 12/13] fix thread logics and nit --- encoding/kzg/prover/parametrized_prover.go | 9 ++++----- encoding/rs/encode.go | 11 ++++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/encoding/kzg/prover/parametrized_prover.go b/encoding/kzg/prover/parametrized_prover.go index e87e5e00f8..af8db1b069 100644 --- a/encoding/kzg/prover/parametrized_prover.go +++ b/encoding/kzg/prover/parametrized_prover.go @@ -225,11 +225,10 @@ func (p *ParametrizedProver) proofWorker( points: nil, err: err, } - continue - } - - for i := 0; i < len(coeffs); i++ { - coeffStore[i][j] = coeffs[i] + } else { + for i := 0; i < len(coeffs); i++ { + coeffStore[i][j] = coeffs[i] + } } } diff --git a/encoding/rs/encode.go b/encoding/rs/encode.go index b6472afb5a..1578804cc8 100644 --- a/encoding/rs/encode.go +++ b/encoding/rs/encode.go @@ -57,7 +57,7 @@ func (g *Encoder) Encode(inputFr []fr.Element) (*GlobalPoly, []Frame, []uint32, return nil, nil, nil, err } - log.Printf(" SUMMARY: RSEncode %v byte among %v numNode with chunkSize %v takes %v\n", + log.Printf(" SUMMARY: RSEncode %v byte among %v numChunks with chunkLength %v takes %v\n", len(inputFr)*encoding.BYTES_PER_COEFFICIENT, g.NumChunks, g.ChunkLength, time.Since(start)) return poly, frames, indices, nil @@ -73,21 +73,21 @@ func (g *Encoder) MakeFrames( if err != nil { return nil, nil, err } - k := uint64(0) + indices := make([]uint32, 0) frames := make([]Frame, g.NumChunks) numWorker := uint64(g.NumRSWorker) - if uint64(numWorker) > g.NumChunks { + if numWorker > g.NumChunks { numWorker = g.NumChunks } jobChan := make(chan JobRequest, numWorker) results := make(chan error, numWorker) - for w := uint64(0); w < uint64(numWorker); w++ { + for w := uint64(0); w < numWorker; w++ { go g.interpolyWorker( polyEvals, jobChan, @@ -96,6 +96,7 @@ func (g *Encoder) MakeFrames( ) } + k := uint64(0) for i := uint64(0); i < g.NumChunks; i++ { j := rb.ReverseBitsLimited(uint32(g.NumChunks), uint32(i)) jr := JobRequest{ @@ -108,7 +109,7 @@ func (g *Encoder) MakeFrames( } close(jobChan) - for w := uint64(0); w < uint64(numWorker); w++ { + for w := uint64(0); w < numWorker; w++ { interPolyErr := <-results if interPolyErr != nil { err = interPolyErr From 12c2526146c72f18d34b39e00b014597f3f830ed Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Fri, 22 Mar 2024 23:23:02 +0000 Subject: [PATCH 13/13] simplify and rm var --- encoding/rs/encode.go | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/encoding/rs/encode.go b/encoding/rs/encode.go index 1578804cc8..65e1a891b4 100644 --- a/encoding/rs/encode.go +++ b/encoding/rs/encode.go @@ -73,7 +73,6 @@ func (g *Encoder) MakeFrames( if err != nil { return nil, nil, err } - indices := make([]uint32, 0) frames := make([]Frame, g.NumChunks) @@ -96,15 +95,12 @@ func (g *Encoder) MakeFrames( ) } - k := uint64(0) for i := uint64(0); i < g.NumChunks; i++ { j := rb.ReverseBitsLimited(uint32(g.NumChunks), uint32(i)) jr := JobRequest{ - Index: uint64(i), - FrameIndex: k, + Index: i, } jobChan <- jr - k++ indices = append(indices, j) } close(jobChan) @@ -147,8 +143,7 @@ func (g *Encoder) ExtendPolyEval(coeffs []fr.Element) ([]fr.Element, []fr.Elemen } type JobRequest struct { - Index uint64 - FrameIndex uint64 + Index uint64 } func (g *Encoder) interpolyWorker( @@ -160,7 +155,6 @@ func (g *Encoder) interpolyWorker( for jr := range jobChan { i := jr.Index - k := jr.FrameIndex j := rb.ReverseBitsLimited(uint32(g.NumChunks), uint32(i)) ys := polyEvals[g.ChunkLength*i : g.ChunkLength*(i+1)] err := rb.ReverseBitOrderFr(ys) @@ -174,7 +168,7 @@ func (g *Encoder) interpolyWorker( continue } - frames[k].Coeffs = coeffs + frames[i].Coeffs = coeffs } results <- nil