Skip to content

Commit cd8f5f4

Browse files
committed
Fix compiling core to JS targets
1 parent 57a3fab commit cd8f5f4

File tree

2 files changed

+127
-22
lines changed

2 files changed

+127
-22
lines changed

core/rawdb/freezer.go

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"fmt"
2222
"math"
2323
"os"
24-
"path/filepath"
2524
"sync"
2625
"sync/atomic"
2726
"time"
@@ -31,7 +30,6 @@ import (
3130
"github.com/ethereum/go-ethereum/log"
3231
"github.com/ethereum/go-ethereum/metrics"
3332
"github.com/ethereum/go-ethereum/params"
34-
"github.com/prometheus/tsdb/fileutil"
3533
)
3634

3735
var (
@@ -84,9 +82,8 @@ type freezer struct {
8482
writeLock sync.Mutex
8583
writeBatch *freezerBatch
8684

87-
readonly bool
88-
tables map[string]*freezerTable // Data tables for storing everything
89-
instanceLock fileutil.Releaser // File-system lock to prevent double opens
85+
readonly bool
86+
tables map[string]*freezerTable // Data tables for storing everything
9087

9188
trigger chan chan struct{} // Manual blocking freeze trigger, test determinism
9289

@@ -114,20 +111,13 @@ func newFreezer(datadir string, namespace string, readonly bool, maxTableSize ui
114111
return nil, errSymlinkDatadir
115112
}
116113
}
117-
// Leveldb uses LOCK as the filelock filename. To prevent the
118-
// name collision, we use FLOCK as the lock name.
119-
lock, _, err := fileutil.Flock(filepath.Join(datadir, "FLOCK"))
120-
if err != nil {
121-
return nil, err
122-
}
123114
// Open all the supported data tables
124115
freezer := &freezer{
125-
readonly: readonly,
126-
threshold: params.FullImmutabilityThreshold,
127-
tables: make(map[string]*freezerTable),
128-
instanceLock: lock,
129-
trigger: make(chan chan struct{}),
130-
quit: make(chan struct{}),
116+
readonly: readonly,
117+
threshold: params.FullImmutabilityThreshold,
118+
tables: make(map[string]*freezerTable),
119+
trigger: make(chan chan struct{}),
120+
quit: make(chan struct{}),
131121
}
132122

133123
// Create the tables.
@@ -137,7 +127,6 @@ func newFreezer(datadir string, namespace string, readonly bool, maxTableSize ui
137127
for _, table := range freezer.tables {
138128
table.Close()
139129
}
140-
lock.Release()
141130
return nil, err
142131
}
143132
freezer.tables[name] = table
@@ -148,7 +137,6 @@ func newFreezer(datadir string, namespace string, readonly bool, maxTableSize ui
148137
for _, table := range freezer.tables {
149138
table.Close()
150139
}
151-
lock.Release()
152140
return nil, err
153141
}
154142

@@ -174,9 +162,6 @@ func (f *freezer) Close() error {
174162
errs = append(errs, err)
175163
}
176164
}
177-
if err := f.instanceLock.Release(); err != nil {
178-
errs = append(errs, err)
179-
}
180165
})
181166
if errs != nil {
182167
return fmt.Errorf("%v", errs)

ethdb/leveldb/fake_leveldb.go

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
// Copyright 2021 The go-ethereum Authors
2+
// This file is part of the go-ethereum library.
3+
//
4+
// The go-ethereum library is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU Lesser General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// The go-ethereum library is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU Lesser General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU Lesser General Public License
15+
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
16+
17+
//go:build js
18+
// +build js
19+
20+
// Package leveldb implements the key-value database layer based on LevelDB.
21+
package leveldb
22+
23+
import (
24+
"errors"
25+
26+
"github.com/ethereum/go-ethereum/ethdb"
27+
)
28+
29+
type Database struct {
30+
unconstructable struct{}
31+
}
32+
33+
// New returns a wrapped LevelDB object. The namespace is the prefix that the
34+
// metrics reporting should use for surfacing internal stats.
35+
func New(file string, cache int, handles int, namespace string, readonly bool) (*Database, error) {
36+
return nil, errors.New("leveldb is unavailable on JS platforms")
37+
}
38+
39+
/*
40+
// NewCustom returns a wrapped LevelDB object. The namespace is the prefix that the
41+
// metrics reporting should use for surfacing internal stats.
42+
// The customize function allows the caller to modify the leveldb options.
43+
func NewCustom(file string, namespace string, customize func(options *opt.Options)) (*Database, error) {
44+
return nil, errors.New("leveldb is unavailable on JS platforms")
45+
}
46+
47+
// configureOptions sets some default options, then runs the provided setter.
48+
func configureOptions(customizeFn func(*opt.Options)) *opt.Options {
49+
// Set default options
50+
options := &opt.Options{
51+
Filter: filter.NewBloomFilter(10),
52+
DisableSeeksCompaction: true,
53+
}
54+
// Allow caller to make custom modifications to the options
55+
if customizeFn != nil {
56+
customizeFn(options)
57+
}
58+
return options
59+
}
60+
*/
61+
62+
// Close stops the metrics collection, flushes any pending data to disk and closes
63+
// all io accesses to the underlying key-value store.
64+
func (db *Database) Close() error {
65+
panic("Method called on unconstructable leveldb database")
66+
}
67+
68+
// Has retrieves if a key is present in the key-value store.
69+
func (db *Database) Has(key []byte) (bool, error) {
70+
panic("Method called on unconstructable leveldb database")
71+
}
72+
73+
// Get retrieves the given key if it's present in the key-value store.
74+
func (db *Database) Get(key []byte) ([]byte, error) {
75+
panic("Method called on unconstructable leveldb database")
76+
}
77+
78+
// Put inserts the given value into the key-value store.
79+
func (db *Database) Put(key []byte, value []byte) error {
80+
panic("Method called on unconstructable leveldb database")
81+
}
82+
83+
// Delete removes the key from the key-value store.
84+
func (db *Database) Delete(key []byte) error {
85+
panic("Method called on unconstructable leveldb database")
86+
}
87+
88+
// NewBatch creates a write-only key-value store that buffers changes to its host
89+
// database until a final write is called.
90+
func (db *Database) NewBatch() ethdb.Batch {
91+
panic("Method called on unconstructable leveldb database")
92+
}
93+
94+
// NewIterator creates a binary-alphabetical iterator over a subset
95+
// of database content with a particular key prefix, starting at a particular
96+
// initial key (or after, if it does not exist).
97+
func (db *Database) NewIterator(prefix []byte, start []byte) ethdb.Iterator {
98+
panic("Method called on unconstructable leveldb database")
99+
}
100+
101+
// Stat returns a particular internal stat of the database.
102+
func (db *Database) Stat(property string) (string, error) {
103+
panic("Method called on unconstructable leveldb database")
104+
}
105+
106+
// Compact flattens the underlying data store for the given key range. In essence,
107+
// deleted and overwritten versions are discarded, and the data is rearranged to
108+
// reduce the cost of operations needed to access them.
109+
//
110+
// A nil start is treated as a key before all keys in the data store; a nil limit
111+
// is treated as a key after all keys in the data store. If both is nil then it
112+
// will compact entire data store.
113+
func (db *Database) Compact(start []byte, limit []byte) error {
114+
panic("Method called on unconstructable leveldb database")
115+
}
116+
117+
// Path returns the path to the database directory.
118+
func (db *Database) Path() string {
119+
panic("Method called on unconstructable leveldb database")
120+
}

0 commit comments

Comments
 (0)