From ad31b75098f874c7124e7b29b47db8662d47b9ff Mon Sep 17 00:00:00 2001 From: Lee Bousfield Date: Thu, 12 Sep 2024 11:17:08 -0500 Subject: [PATCH] Move wasm-only code into wasm build flags --- core/rawdb/accessors_snapshot.go | 15 ------------ core/rawdb/arbitrum_not_found.go | 26 ++++++++++++++++++++ core/rawdb/arbitrum_not_found_native.go | 32 +++++++++++++++++++++++++ core/rawdb/arbitrum_not_found_wasm.go | 30 +++++++++++++++++++++++ 4 files changed, 88 insertions(+), 15 deletions(-) create mode 100644 core/rawdb/arbitrum_not_found.go create mode 100644 core/rawdb/arbitrum_not_found_native.go create mode 100644 core/rawdb/arbitrum_not_found_wasm.go diff --git a/core/rawdb/accessors_snapshot.go b/core/rawdb/accessors_snapshot.go index 6b6b0ff174..8c72c28482 100644 --- a/core/rawdb/accessors_snapshot.go +++ b/core/rawdb/accessors_snapshot.go @@ -18,14 +18,10 @@ package rawdb import ( "encoding/binary" - "errors" - "github.com/cockroachdb/pebble" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/ethdb" - "github.com/ethereum/go-ethereum/ethdb/memorydb" "github.com/ethereum/go-ethereum/log" - "github.com/syndtr/goleveldb/leveldb" ) // ReadSnapshotDisabled retrieves if the snapshot maintenance is disabled. @@ -76,17 +72,6 @@ func DeleteSnapshotRoot(db ethdb.KeyValueWriter) { } } -func isDbErrNotFound(err error) bool { - return errors.Is(err, leveldb.ErrNotFound) || errors.Is(err, pebble.ErrNotFound) || errors.Is(err, memorydb.ErrMemorydbNotFound) -} - -func ignoreNotFound(blob []byte, err error) ([]byte, error) { - if isDbErrNotFound(err) { - return nil, nil - } - return blob, err -} - // ReadAccountSnapshot retrieves the snapshot entry of an account trie leaf. func ReadAccountSnapshot(db ethdb.KeyValueReader, hash common.Hash) ([]byte, error) { return ignoreNotFound(db.Get(accountSnapshotKey(hash))) diff --git a/core/rawdb/arbitrum_not_found.go b/core/rawdb/arbitrum_not_found.go new file mode 100644 index 0000000000..2c335a4e34 --- /dev/null +++ b/core/rawdb/arbitrum_not_found.go @@ -0,0 +1,26 @@ +// Copyright 2024 The go-ethereum Authors +// This file is part of the go-ethereum library. +// +// The go-ethereum library is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// The go-ethereum library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with the go-ethereum library. If not, see . + +package rawdb + +// Arbitrum specific code to handle database errors + +func ignoreNotFound(blob []byte, err error) ([]byte, error) { + if isDbErrNotFound(err) { + return nil, nil + } + return blob, err +} diff --git a/core/rawdb/arbitrum_not_found_native.go b/core/rawdb/arbitrum_not_found_native.go new file mode 100644 index 0000000000..3543aedc8d --- /dev/null +++ b/core/rawdb/arbitrum_not_found_native.go @@ -0,0 +1,32 @@ +// Copyright 2024 The go-ethereum Authors +// This file is part of the go-ethereum library. +// +// The go-ethereum library is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// The go-ethereum library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with the go-ethereum library. If not, see . + +//go:build !wasm +// +build !wasm + +package rawdb + +import ( + "errors" + + "github.com/cockroachdb/pebble" + "github.com/ethereum/go-ethereum/ethdb/memorydb" + "github.com/syndtr/goleveldb/leveldb" +) + +func isDbErrNotFound(err error) bool { + return errors.Is(err, leveldb.ErrNotFound) || errors.Is(err, pebble.ErrNotFound) || errors.Is(err, memorydb.ErrMemorydbNotFound) +} diff --git a/core/rawdb/arbitrum_not_found_wasm.go b/core/rawdb/arbitrum_not_found_wasm.go new file mode 100644 index 0000000000..d49c96848e --- /dev/null +++ b/core/rawdb/arbitrum_not_found_wasm.go @@ -0,0 +1,30 @@ +// Copyright 2024 The go-ethereum Authors +// This file is part of the go-ethereum library. +// +// The go-ethereum library is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// The go-ethereum library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with the go-ethereum library. If not, see . + +//go:build wasm +// +build wasm + +package rawdb + +import ( + "errors" + + "github.com/ethereum/go-ethereum/ethdb/memorydb" +) + +func isDbErrNotFound(err error) bool { + return errors.Is(err, memorydb.ErrMemorydbNotFound) +}