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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix concurrent map accessing caused panic #2073

Merged
merged 2 commits into from Feb 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 6 additions & 2 deletions code/go/0chain.net/chaincore/block/entity.go
Expand Up @@ -180,11 +180,15 @@ func NewBlock(chainID datastore.Key, round int64) *Block {
return b
}

func (b *Block) GetUniqueBlockExtensions() (uBlExts map[string]bool) {
func (b *Block) GetUniqueBlockExtensions() map[string]bool {
b.uniqueBlockExtMutex.RLock()
defer b.uniqueBlockExtMutex.RUnlock()

return b.uniqueBlockExtensions
cb := make(map[string]bool, len(b.uniqueBlockExtensions))
for k, v := range b.uniqueBlockExtensions {
cb[k] = v
}
return cb
}

// GetVerificationTickets of the block async safe.
Expand Down
4 changes: 1 addition & 3 deletions code/go/0chain.net/core/encryption/signature_scheme.go
Expand Up @@ -5,8 +5,6 @@ import (
"errors"
"fmt"
"io"

"github.com/0chain/common/core/encryption"
)

const (
Expand Down Expand Up @@ -180,7 +178,7 @@ func VerifyPublicKeyClientID(pubKey string, clientID string) error {
return fmt.Errorf("invalid public key: %v", err)
}

if encryption.Hash(pubKeyBytes) != clientID {
if Hash(pubKeyBytes) != clientID {
return fmt.Errorf("mismatched public key and client ID")
}

Expand Down
5 changes: 4 additions & 1 deletion code/go/0chain.net/miner/miner_test.go
Expand Up @@ -5,14 +5,15 @@ import (
"context"
"flag"
"fmt"
"github.com/alicebob/miniredis/v2"
"log"
"os"
"os/user"
"strconv"
"testing"
"time"

"github.com/alicebob/miniredis/v2"

"0chain.net/chaincore/state"
"0chain.net/smartcontract/setupsc"

Expand Down Expand Up @@ -239,6 +240,8 @@ func TestBlockVerification(t *testing.T) {
func TestTwoCorrectBlocks(t *testing.T) {
cleanSS := SetUpSingleSelf()
defer cleanSS()

config.SetupSmartContractConfig("testdata")
ctx := context.Background()
mr := CreateMockRound(1)
mr.RandomSeed = time.Now().UnixNano()
Expand Down